in reply to Ignore certain return values
You should be aware of Context (perl.com). The wantarray builtin tells you the calling context:$ perl -wl sub get_values { return ('a', 'b', 'c'); } my $result = undef; $result = get_values(); print $result; ($result) = get_values(); print $result; __END__ c a
There are several modules that addresses context and return values, e.g. Contextual::Return.$ perl sub check_context { # True if ( wantarray ) { print "List context\n"; } # False, but defined elsif ( defined wantarray ) { print "Scalar context\n"; } # False and undefined else { print "Void context\n"; } } my @x = check_context(); # prints 'List context' my %x = check_context(); # prints 'List context' my ($x, $y) = check_context(); # prints 'List context' my $x = check_context(); # prints 'Scalar context' check_context(); # prints 'Void context' __END__ List context List context List context Scalar context Void context
|
|---|