[Omaha.pm] my $a = blah();

Andy Lester andy at petdance.com
Tue Apr 4 18:59:28 PDT 2006


> $ cat j.pl
> my $a = blah();
> print "$a\n";
>
> sub blah {
>    return (7,8);
> }
>
> $ perl j.pl
> 8

Perl knows that blah() is being called in scalar context, so it  
evaluates (7,8) in scalar context, which is 8, because it's the  
rightmost value after the comma.

Now, if you'd said

my ($a) = blah();

then $a will be 7, and 8 gets ignored.

xoxo,
Andy


--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20060405/64a57988/attachment.html


More information about the Omaha-pm mailing list