Created
April 3, 2014 06:50
-
-
Save abuzarhamza/9949444 to your computer and use it in GitHub Desktop.
wantarray Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#called under void context | |
testContextCall(); | |
#called under scalar context | |
my $test = testContextCall(); | |
#called under list context | |
my @test = testContextCall(); | |
print "testContextCall() under scalar contex : $test\n"; | |
print "testContextCall() under array contex : @test\n"; | |
sub testContextCall { | |
if (wantarray()) { | |
return qw(1 2 3); | |
} | |
else { | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment