February 2012
Intermediate to advanced
1184 pages
37h 17m
English
wantarray
This function returns true if the context of the currently
executing subroutine is looking for a list value, and false otherwise.
The function returns a defined false value ("") if the calling context is looking for a
scalar, and the undefined false value (undef) if the calling context isn’t looking
for anything; that is, if it’s in void context.
Here are examples of typical usage:
return unless defined wantarray; # don't bother doing more my @a = complex_calculation(); return wantarray ? @a : \@a;
See also caller. This function
should really have been named “wantlist”, but we named it back when list
contexts were still called array contexts.
Read now
Unlock full access