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.