in reply to Re: hash & arrays
in thread hash & arrays

What I tried doing (and failed) was the following: $hash{$empid} = $title, $adjst, $adjst2, $linex; "$linex" is actually an array with a number of variables and the other "substitution" variables are created earlier in the program. In executing this, Perl gave me the word "ARRAY" followed by an 0x hex string and then a 1 when I tried printing the first value. Can I not use the $ variables within the hash structure?

Replies are listed 'Best First'.
Re^3: hash & arrays
by colwellj (Monk) on Nov 02, 2009 at 23:04 UTC
    Spooky,

    you can always explicitly define the type so instead of $linex (a pointer to an array) you can use "@{$linex}", my SCALAR is actually a list, honest.

    cheers

    John
      I tried the the following: @hash{$emp_id} = split(/a-z{2,5}A-Z{2,5}/,$linex); Now, this splits "linex" very nicely but I'm not sure how to access individual "elements" with the split. I know how to do this with an array but not sure about the syntax required using a hash structure.
        Spooky, try this.
        my %hash = []; #explicitly create a hash of arrays structure for clari +ty #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 #then to get a particular emement print OUTPUT $hash{$userid}[0]; #prints $title for that user
        John