On Aug 29, 2:52 am, [EMAIL PROTECTED] (John W. Krahn) wrote:
> >            return undef;
>
> You normally don't need to return undef, perl will do the right thing and
> correctly distinguish between list and scalar context.

I'd go one level more - it's not just unnecessary, it's generally
wrong.  If the user does call your subroutine in list context by
assigning to an array, and then tests the truth of the array, they
will get incorrect results.

sub foo {
   return undef;
}
my $foo = foo();
if ($foo) { #false!!
   ...
}
my @foo = foo();
if (@foo) { #true!!!
   ...
}

sub bar {
   return;
}
my $bar = bar();
if ($bar) { #false!!
   ...
}
my @bar = bar();
if (@bar) { #false!!
  ...
}


The problem is that an array that contains one element is true, no
matter what that element is.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to