Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(Ovid) Re: Efficiency of multiple if statements

by Ovid (Cardinal)
on May 09, 2001 at 01:03 UTC ( [id://78960]=note: print w/replies, xml ) Need Help??


in reply to Efficiency of multiple if statements

Well, if you don't have anything in the if block, why not put everything in the one if test? The following is a cleaner example (IMHO) and I've used character classes because they tend to be more efficient than the the /i modifier (they work here only because you had simple regexes). Also, I broke the regexes out into separate tests rather than use the inefficient alternations.

#see if it hasn't been touched in 3 days if (-M "$logdir/$f" > 3.0 and #see if file begins with ab or def ( $f =~ /^[Aa][Bb]/ or $f =~ /^[Dd][Ee][Ff]/ ) and #see if hasn't been zipped already ! ($f =~ /gz\b/ ) ) { system ("/usr/local/bin/gzip", "$logdir/$f"); }

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-25 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found