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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
At least, if not to combine the regexes (since one is a affrimative case, one negative), but to combine everything into one if statement:
if ( ( -M "$logdir/$f" > 3.0 ) && ( $f =~ /^(ab|def)/i ) && ( $f !~ /gz\b/ ) ) { system ( "/usr/local/bin/gzip", "$logdir/$f" ); }
The perl interpreter is smart enough to recongize when it can short-circuit the above operation when it encounters a false statement; that is, if the -M operative fails, the regexs should never be performed. Not only that, this, IMO, is much easier to read and understand ("Oh, this system call only happens when these 3 conditions are met..."), and much more maintainable.

Mind you, I'm assuming here that you want to take no alternate actions if those if statements fail. If you do, you need seperate else statements as your code above is ready for.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

In reply to Re: Efficiency of multiple if statements by Masem
in thread Efficiency of multiple if statements by scottstef

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found