Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: if not defined

by Trihedralguy (Pilgrim)
on Mar 23, 2007 at 18:18 UTC ( [id://606320]=note: print w/replies, xml ) Need Help??


in reply to if not defined

Thats very odd that you have to do either "not..and" or "!..&&".
if (not defined($pname) and $pname eq '' && defined($policy_ur) and $p +olicy_ur eq '' and not defined($odate) && $odate eq'') {

That works famously! - Thanks everyone and pKai :)

Replies are listed 'Best First'.
Re^2: if not defined
by TGI (Parson) on Mar 23, 2007 at 18:36 UTC

    Is this really what you mean?

    ( ( ( not defined($pname) ) and ( $pname eq '' && defined($policy_ur) ) ) and $policy_ur eq '' ) and ( not ( defined($odate) && $odate eq'' ) )

    Please take the time to read about operator precedence. That perl has logical operators with two levels of precendence is very useful, but it is a trap for the unwary or unaware.

    If you don't pay attention to precedence you'll think the answer to 2+3*5 is 25. Even worse, if you have code to implement X+Y*Z that uses bad precedence, and you test your code with X, Y and Z all being 1, you'll believe the code works. Then six months later, Bob in accounting is wanting to know where $5 million went...


    TGI says moo

Re^2: if not defined
by pKai (Priest) on Mar 23, 2007 at 18:38 UTC
    hm,
    ... and not defined($odate) && $odate eq '')
    is testing if it's "not defined" (i. e. undef) and then if it's also equals the empty string.

    Thinking about it, both can never be true at the same time.

    Update: Oh well, twice in a row on the wrong track. :-(

    TGI has the precedence right and the problem lies in the first part, not in the second I cited.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found