in reply to Re: wantarray documentation in 5.8.7
in thread wantarray documentation in 5.8.7
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: wantarray documentation in 5.8.7
by tlm (Prior) on Jul 25, 2005 at 16:17 UTC | |
by polettix (Vicar) on Jul 25, 2005 at 16:42 UTC | |
by Anonymous Monk on Jul 26, 2005 at 00:39 UTC | |
|
Re^3: wantarray documentation in 5.8.7
by themage (Friar) on Jul 25, 2005 at 14:23 UTC |