Yes - everything does get 'squashed'. Internally, an array and a hash are much the same - it's just a hash is an array with an even number of paired values. So you can coerce from hash to array and back again. That's what's happening here.
Probably the easiest way of handling passing a whole hash into a subroutine is by reference. E.g. invoke your sub with:
my_sub ( $value, \%myhash );
And within the sub:
my ( $value, $hashref ) = @_; foreach my $key ( keys %$hashref ) { print "$key = $$hashref{'$key'}\n"; }
Although you should note that a has passed by reference - if you modify it within the sub, it'll modify the 'source instance'. Read 'perlref' for more detail.
In reply to Re^2: Passing a scalar and hash as subroutine arguments
by Preceptor
in thread Passing a scalar and hash as subroutine arguments
by jktstance
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |