Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Count and List Items in a List

by holli (Monsignor)
on Nov 01, 2005 at 16:13 UTC ( #504627=note: print w/ replies, xml ) Need Help??


in reply to Count and List Items in a List

You better move that array splitting into your conditional, like so:

if (m/zaps/i) { @zapschool = split (/\t/); print NEWFILE "$zapschool[4]\n"; }
That will give you a performance boost because in your code all line get split, here just the neccessary lines.

Please note (good to impress your boss :) that you can do this in a oneliner:
C:\>perl -naF/\t/ -e "print qq($F[4]\n) if /zaps/" infile>outfile
or the counting:
C:\>perl -naF/\t/ -e "$hash{$F[4]}++ if /zaps/;END{print qq($_\t$hash{ +$_}\n) for sort keys %hash}" infile>outfile


holli, /regexed monk/


Comment on Re: Count and List Items in a List
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://504627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-07-31 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls