develooper Front page | perl.perl5.porters | Postings from January 2009

Context of early elements of list in scalar context

Thread Next
From:
Eric Brine
Date:
January 11, 2009 13:58
Subject:
Context of early elements of list in scalar context
Message ID:
f86994700901111358t20e30e23mc69a12c70060bf3a@mail.gmail.com
Is there a reason for the following difference in behaviour?

use strict;
use warnings;

sub f {
   if ( wantarray() ) {
      print "list\n";
   }
   elsif ( defined wantarray() ) {
      print "scalar\n";
   }
   else {
      print "void\n";
   }
}

my $x =     ( f(), f(), f() );      print("\n");  # v,v,s
my $y = sub { f(), f(), f() }->();  print("\n");  # s,s,s

(Perl 5.6.0, 5.6.1, 5.8.0, 5.8.8, 5.10.0)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About