in reply to hash ref 101
Parameters passed to a function get flattened into a list, which is placed in @_. So, in your code above at line 11: @_ = qw(uno one dos two tres three).
Basically, you aren't passing a hash reference. You are trying to pass a hash directly. Hashes can be converted to lists easily, so that's what happens.
There are two ways to do what you want to do, off the top of my head. (With minimal modification to your code.) First is to convert the list back into a hash:
sub hash { my %param = @_; # I hope I'm remembering this right... print $param{uno}, "\n"; }
The second, (and in my opinion better, especially if you are going to be working with objects, where another parameter will be automatically passed) is to actually pass a hashref:
hash( { uno => 'one', dos => 'two', tres => 'three', } ); sub hash { my ($param) = @_; print $param->{uno}, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash ref 101
by AnomalousMonk (Archbishop) on Dec 17, 2008 at 14:41 UTC | |
by gmoque (Acolyte) on Dec 18, 2008 at 01:59 UTC |