Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2015-07-28 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls