in reply to hash & arrays

my %hash; $hash{ewh1234} = ['engineer', 23.4, 1.2, 'local']; # value for key ewh1234 is a reference to an anonymous array .... print "@{$hash{ewh1234}}\n"; # will print the array print "$hash{ewh12134}[1]\n"; # will print 23.4 ....
Update: corrected typo (thanks Crackers2)

Replies are listed 'Best First'.
Re^2: hash & arrays
by Spooky (Beadle) on Nov 02, 2009 at 17:24 UTC
    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?
      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.