First off I apoligize if this has been asked before, but I couldn't find a post that met my needs. I'm pretty new to perl, so I think this is a fairly simple question. I have a loop that goes over a file, and parses out the username, and the project that user works on from the file. I then want to put the project name as a key into a hash, and then have an array of users that is associated to that key. I am currently trying to do that by:
1. foreach (@ufile_contents) 2. { 3. ($buser2,$email,$project) = split(/\|/,$_); 4. if($uo_hash{lc($buser2)} =~ /WO/) 5. { 6. @usr_list = $wo_usr_proj{$project}; 7. push(@usr_list,$buser2); 8. $wo_usr_proj{$project} = @usr_list; 9. } 10. }
the if statement just makes sure that the user belongs to a certain office before it gets put into the hash. the hash is wo_usr_proj, and I want to use @usr_list for the hash value. when I check what @usr_list is set to after line 6 I see that its just an empty array, so when I push something on to it, I'm getting a two item array. this is true through out the whole execution of the code, not just on the first step. Also, shouldn't it be a single item array after the push since the initial array was empty. I'm getting an empty slot and then the username when I print out the array. Any ideas on what I'm doing wrong? thanks in advance.

In reply to dealing with arrays as hash values by goonarific

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.