Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Grep Speeds

by arhuman (Vicar)
on Feb 06, 2001 at 20:10 UTC ( [id://56681]=note: print w/replies, xml ) Need Help??


in reply to Grep Speeds

What about this one-line ?

Here are the main ideas :

You read the file only once !
Then you try for each line to match one of your paterns...
You don't use backquotes as they spawn a shell and it's very cpu/memory consuming...

perl -ne ' foreach $item(@timearray) { $searchstring = "$NETID\|$month +\/$date\/$year\|$item\|"; if (/"^$searchstring/) { print }}' /PHL/dat +a1/PHL/tmp/ECL_STAT.txt

Of course it could be optimized (for example I try to match all the remaining patterns even if I got a match, this seems to be unnecessary...)
Anyway, IMHO your main mistake is to open/read the file several time !

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found