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"; }

In reply to Re: hash ref 101 by DStaal
in thread hash ref 101 by gmoque

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.