Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(Ovid) Re: Efficiency of multiple if statements

by Ovid (Cardinal)
on May 09, 2001 at 01:03 UTC ( #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
Node Status?
node history
Node Type: note [id://78960]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-04-17 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?