[Omaha.pm] not defined $j || scalar @$j == 0

Jay Hannah jhannah at omnihotels.com
Mon Apr 10 04:22:28 PDT 2006


I settled for this pattern. My what-to-do block has to appear twice.
ick.

j

 
if (not defined $j) {
   print "yup\n";
} elsif (scalar @$j == 0) {
   print "yup\n";
}



> -----Original Message-----
> From: Jay Hannah 
> Sent: Monday, April 10, 2006 11:18 AM
> To: 'omaha-pm at pm.org'
> Subject: not defined $j || scalar @$j == 0
> 
> 
> Doh. "use strict" pukes even when a short-circuit operator 
> stops the right side from being evaluated...
> 
> I was trying to have my if test below trap when
>    (1) $j is undef
>    (2) $j is [ ]
> 
> But apparently "use strict" is too... mmm... strict.
> 
> j
> 
> 
> $ cat j.pl
> use strict;
> 
> my $j;
> if (not defined $j || scalar @$j == 0) {
>    print "yup\n";
> }
> 
> $ perl j.pl
> Can't use an undefined value as an ARRAY reference at j.pl line 4.
> 
> 


More information about the Omaha-pm mailing list