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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062468]
[shmem]: perldigious: as always - if it ain't broke, don't fix it. Ther must be a very compelling reason for changing column names in a database. Those are rare.
[Corion]: If you have whitespace in the column names in the database, whap the DBAs ;)
[shmem]: It's common for some vendors to have column names such as WRSTVG or some other such whizzbang, and another table where these names are mapped to something meaningful depending on how you look at the data
[shmem]: afair in SAP that occurs all the time

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2017-05-25 13:38 GMT
Find Nodes?
    Voting Booth?