in reply to Array Element Occurence

Use a hash...it's good at counting arbitrary numbers of arbitrary things:
my $recordfile = "/foo/bar/copy.txt"; my %record; open (FILE, "$recordfile") or die "Can't open $recordfile: $!\n"; while(<FILE>) { if (/^(..)/) { $record{$1}++; } } print "The Total number or records = $.\n\n"; for (sort keys %record) { print "$_ reports $record{$_} records.\n"; } ## Or, to output the records from fewest to most: for (sort {$record{$a} <=> $record{$b} or $a cmp $b} keys %record) { print "$_ reports $record{$_} records.\n"; }

Replies are listed 'Best First'.
Re: Array Element Occurence
by entr00pi (Scribe) on Sep 12, 2000 at 20:09 UTC
        While you are getting into the swing of things, make sure you use use strict; at the top of your program.

        The program you posted will then complain horribly about barewords (ooooh nakidity ;-) which are useful when writing perl poetry, but not in my experience when you are writing code you ever want to look at again!

        TIMTOWDI of course, but that is my way!