Your example code isn't doing what you're saying it is...

my %hash = []; #explicitly create a hash of arrays structure for clari +ty

This doesn't mean anything, and is in fact an error; you can't assign a single scalar (an array reference in this case) to a hash.

#push your items into the array - this will create the hash $userid if + it dosent already exist push @{$hash{$userid}}, ($title, $adjst, $adjst2, @{$linex}) #@{$linex) says i am a list

$userid isn't a hash. %hash is. $hash{$userid} is a hash element. In saying @{$hash{$userid}} you're asking perl to treat that hash element as an array reference, and dereference it; in this case, the element doesn't exist, and so is created as what it ostensibly is (an array ref), and then used via push to push those elements onto it. The parenthesis are unnecessary and don't mean anything here.

Also, $linex in his code sounds like a string, not an array ref.


In reply to Re^6: hash & arrays by fullermd
in thread hash & arrays by Spooky

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.