Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: if not defined

by pKai (Priest)
on Mar 23, 2007 at 18:10 UTC ( #606315=note: print w/replies, xml ) Need Help??


in reply to if not defined

For one, it's valid Perl syntax:
D:\Temp>perl -c -e "if (not defined($pname) && $pname ne '' && defined +($policy_ur) && $policy_ur ne '' && not defined($odate) && $odate ne +''){}" -e syntax OK
But it's probably not doing what you expect:
D:\Temp>perl -MO=Deparse,p -e "if (not defined($pname) && pname ne '' +&& defined($policy_ur) && $policy_ur ne '' && not defined($odate) && +$odate ne ''){}" if (not defined $pname && $pname ne '' && defined $policy_ur && $polic +y_ur ne '' && !(defined $odate && $odate ne '')) { (); } -e syntax OK
not has a much lower precedence than &&

use either not and and or ! and && in conjunction to get the intended effect.

Update: Seems like newly accuired syntax highlighting was distracting me ;-). Though a little bit complicated the assembly of the leading not (inverting the result of the whole test) with the && (chaining all the inner sub-tests together) makes sense.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606315]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2021-04-16 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?