First script /tmp/prova1.pl uses wantarray at the top level of a file:
When called directly, it yelds:#!/usr/bin/perl wantarray ? print("wantarray!\n") : defined wantarray ? print("wantarray defined but false\n") : print("wantarray undefined!\n"); wantarray ? qw( ciao a tutti ) : defined wantarray && "howdy!";
but here I agree with you, we cannot rely on it. This is why I built the second script /tmp/prova2.pl:wantarray undefined!
which yelds:#!/usr/bin/perl use strict; use warnings; $" = ", "; print "First: list context\n"; my @a = do '/tmp/prova1.pl'; print "array \@a = (@a)\n\n"; print "Second: void context\n"; do '/tmp/prova1.pl'; print "\nThird: scalar context\n"; my $c = do '/tmp/prova1.pl'; print "scalar \$c = $c\n";
So, the wantarray is used "at the top of the file", but it seems that wantarray is working fine. Can we rely on it? If yes, I think that the docs should be made a little clearer.First: list context wantarray! array @a = (ciao, a, tutti) Second: void context wantarray undefined! Third: scalar context wantarray defined but false scalar $c = howdy!
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
In reply to Re^2: wantarray documentation in 5.8.7
by polettix
in thread wantarray documentation in 5.8.7
by polettix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |