in reply to Count and List Items in a List
is slower thanwhile (<FILE>) { @zapschool = split (/\t/); if (m/zaps/i) { print NEWFILE "$zapschool[4]\n"; } }
which can be made more readable aswhile (<FILE>) { if (m/zaps/i) { @zapschool = split(/\t/); print NEWFILE "$zapschool[4]\n"; } }
And the solution iswhile (<FILE>) { if (m/zaps/i) { my $zapschool = (split(/\t/))[4]; print NEWFILE "$zapschool\n"; } }
my %count; while (<FILE>) { if (m/zaps/i) { my $zapschool = (split(/\t/))[4]; ++$count{$zapschool}; } } foreach (keys(%count)) { print NEWFILE "$_: $count{$_}\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Count and List Items in a List
by Tech77 (Novice) on Nov 02, 2005 at 19:32 UTC |