scriptinperl has asked for the wisdom of the Perl Monks concerning the following question:

I have a file with near about 20 columns, now all i need is i have to work on particular column , say species column.
In my species column i have several species and some of them are repeated .
Now i need to know the code for
1) list of all species names there in the Record and their count.
2)The second part is a list of unique species in those species column and the count of occurs.
Thank You

Replies are listed 'Best First'.
Re: Working on a file.
by zwon (Abbot) on Jan 20, 2010 at 18:57 UTC

    And the file format is...

    Are columns separated by spaces, or is it CSV file, or is it some XML format?

    If you already read file and have column stored in array, let's call it @species then it is simple:

    my %hash; for (@species) { $hash{$_}++; } print "Number of different species: ", 0+(keys %hash), "\n"; for (sort keys %hash) { print "$_: ", $hash{$_}, "\n"; }
      It is a CSV File Zwon.

        Then have a look on Text::CSV, it will allow you to parse your file.

Re: Working on a file.
by CountZero (Bishop) on Jan 20, 2010 at 22:10 UTC
    Or have a look at DBI and DBD::CSV. It allows you to access your file as a database and use SQL to get your answers.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Working on a file.
by BioLion (Curate) on Jan 20, 2010 at 19:05 UTC

    scriptinperl - this isn't a code writing service! If you want help, you'll need to at least give us some code that you have tried and some example data...

    Just a something something...