in reply to testing defined($x) && length($x)

Why are you not just doing this?
if ($x and length($x)) {} # Do something

This should take care of your $x not being defined.

Update: Too early did not think clearly see below. Removed the offending/incorrect text.

Replies are listed 'Best First'.
Re^2: testing defined($x) && length($x)
by kennethk (Abbot) on Mar 25, 2009 at 16:34 UTC

    No, it still has the '0' false negative:

    $ perl -e '$x = 0; print "failed\n" unless $x and length($x)' failed $

    vs.

    $ perl -e '$x=0; $ print "failed\n" unless defined $x and length($x)' $

Re^2: testing defined($x) && length($x)
by Bloodnok (Vicar) on Mar 25, 2009 at 16:41 UTC
    ...length test will catch it if the value of $x = 0, hmmm, if $x == 0, then length() test will not be executed - aka, it suffers from the same problem (with my attempt) that ikegami kindly pointed out.

    A user level that continues to overstate my experience :-))