[Omaha.pm] Precedence && vs or

Jay Hannah jhannah at omnihotels.com
Tue Apr 17 15:53:23 PDT 2007


Huh. This was dying when $last_elt wasn't defined:

$last_elt->paste(last_child => $controls) or die;

So I changed it to this:

$last_elt && $last_elt->paste(last_child => $controls) or die;

Thinking the && would short-circuit the rest if $last_elt wasn't
defined. It doesn't. Here's a demo:

--------
$ cat j.pl
my $j;
$j && $j->what or die;

$ perl j.pl
Died at j.pl line 4.
--------

Oops. Adding parens gets me to the behaviour I expected:

--------
$ cat j.pl
my $j;
$j && ($j->what or die);

$ perl j.pl
$
--------

Live and learn.  :)

j



More information about the Omaha-pm mailing list