Skip to content

Instantly share code, notes, and snippets.

@abuzarhamza
Created April 3, 2014 06:50
Show Gist options
  • Save abuzarhamza/9949444 to your computer and use it in GitHub Desktop.
Save abuzarhamza/9949444 to your computer and use it in GitHub Desktop.
wantarray Tutorial
#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