Perl Home
PERL Functions
© 2011 TutorialsPoint.COM
|
PERL wantarray Function
Syntax
Definition and Usage
Returns true if the context of the currently executing function is looking for a list value.
Returns false in a scalar context.
Return Value
Example
#!/usr/bin/perl -w
sub foo {
return(wantarray() ? qw(A, B, C) : '1');
}
$result = foo(); # scalar context
@result = foo(); # array context
print("foo() in a scalar context: $result\n");
print("foo() in an array context:
@result\n");
|
It will produce following results:
foo() in a scalar context: 1
foo() in an array context:
A, B, C
| |
|

|
|
|