Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by sundialsvc4 (Monsignor)
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)
Re^2: Help choosing the most efficient, dependable condition(al)
by boftx (Chaplain) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-09-01 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (11 votes), past polls