in reply to wantarray like wanthash

wantarray should perhps be called something like callcontext. For this purpose Perl has three contexts: void, scalar and list, and wantarray is undef, false and true.

Note in general that in list context a hash turns into an array in any case - think for example what happens when you pass a hash into a sub. To that extent hashes and arrays are interchangeable.

Consider this:

use warnings; use strict; use Data::Dumper; my %hash = (first => '1', second => '2'); print "Original: " . Dumper (\%hash); my %newHash = %{inAndOut (%hash)}; print "\nnew hash: " . Dumper (\%newHash); sub inAndOut { my (%hash) = @_; print "\nin sub: " . Dumper (\%hash); return {%hash}; }

prints:

Original: $VAR1 = { 'first' => '1', 'second' => '2' }; in sub: $VAR1 = { 'first' => '1', 'second' => '2' }; new hash: $VAR1 = { 'first' => '1', 'second' => '2' };

DWIM is Perl's answer to Gödel