[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@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.
> 
>