Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Help choosing the most efficient, dependable condition(al)

by sundialsvc4 (Abbot)
on Nov 13, 2013 at 20:43 UTC ( #1062468=note: print w/replies, xml ) Need Help??


in reply to Help choosing the most efficient, dependable condition(al)

Without trying to dumpster-dive into this particular debate, I would note that it is easy to avoid messages like “use of uninitialized value” through the use of the && (logical-AND) operator, which uses so-called short circuit evaluation:   if the left-hand side is False, the right-hand side is not evaluated at all.   (See perldoc perlop.)

Thus, you can say (say...):
if ( $ENV{'HTTP_ACCEPT'} && ( $ENV{'HTTP_ACCEPT'} =~ ...

undef is always False.   So, the statement quits right there and the remainder of the expression is never evaluated.

  • Comment on Re: Help choosing the most efficient, dependable condition(al)

Replies are listed 'Best First'.
Re^2: Help choosing the most efficient, dependable condition(al)
by boftx (Deacon) on Nov 13, 2013 at 21:44 UTC

    The preceding is a good way to go, but it you want slightly simpler I've done this before:

    if (($ENV{'HTTP_ACCEPT'} || '') =~ /application\/xhtml\+xml/) { print "content-type:application/xhtml+xml; charset=utf-8\n\n"; }else{ print "content-type:text/html; charset=utf-8\n\n"; }
    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062468]
help
Chatterbox?
[Corion]: Hmmm. I feel a Meditation coming on. I wrote a module, DBIx::PivotQuery, which returns a table-like set of rows (AoA) but some columns are generated from column values, like in an (Excel) pivot table or a ROLLUP command
[Corion]: My current approach for subtotals involves rerunning the given query, with the hint to the user that they should use a temporary table if they want better performance.
[Corion]: But I could create that temporary table in the module and use it for the improved perfomance directly instead.
[Corion]: And the question is, what would be better/preferred ;-)
[Corion]: Hmm - not exactly like the ROLLUP command. Ah well.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2017-02-23 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (347 votes). Check out past polls.