Re: csv file question

[email protected] (Gunnar Hjalmarsson)
Newsgroups perl.beginners
Message-ID <[email protected]>
Anirban Adhikary wrote:
> I have a csv file having the following contents.
> col1 col2 col3
> "A", "1","2"
> "B","1",   "3"
> "C","2","4"
> "D","1","5"
> "A","1","6"
> "B","2","7"
> "C","2","8"
> " ","3","9"
> 
> Now I want to implement a logic which will show me the summarize records as
> follows
> col1 count
> A-   2
> B -  2
> C -  2
> D -  1

     my %cnt;
     /^"(\w+)"/ and $cnt{$1}++ while <>;
     print "col1 count\n";
     print "$_ -  $cnt{$_}\n" for sort keys %cnt;

> and one more question how the null value will be handled

Are you expecting _us_ to know that??

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.