http://www.perlmonks.org?node_id=208366


in reply to Hash of arrays

I think the bit you're missing is that a reference is a scalar. So instead of this:

while ( ($key, @value) = each %id_veritasHash){

You need this:

while ( ($key, $value) = each %id_veritasHash){

Then to loop through the items in the array that the scalar $value references, instead of this:

foreach $temp (@value){

You need this:

foreach $temp (@$value){

The final bit of the puzzle is that each of your references points to the same array (the output from your code shows the same hex value in the stringified reference). To create a different array each time through the loop, instead of this:

@data = split /\t/, $line;

You need this:

my @data = split /\t/, $line;

There are other ways to create new arrays, which you can read about in perlreftut.

Replies are listed 'Best First'.
Re: Re: Hash of arrays
by heezy (Monk) on Oct 27, 2002 at 20:13 UTC

    Both of the replies to my posting were fantastic thanks guys! Up voting all round!

    M