in reply to multidimensional hash of array

A simple solution is two concatenate the two keys into one with a seldom used character. In fact, that's what Perl does internally when you give several keys to index a hash:

$myhash{'key1', 'key2'};

is equivalent to:

$myhash{join("\x1c", 'key1', 'key2')};

ASCII 28 is considered a seldom used character, but you may use another one by changing $;.

Needless to say this is widely considered dirty. davorg's suggestion of using a hash of hashes of arrays is a lot neater.

HTH

--bwana147

Replies are listed 'Best First'.
Re: Re: multidimensional hash of array
by kevyt (Scribe) on May 31, 2001 at 20:26 UTC
    I would like to thank everyone for their help
    I currently have:
    foreach(@info){ $_=~ s/^\s+//; @str = split; if( $myhash{$str[2]}{$str[0]} ){ # if same connection type al +ready stored ( $myhash{$str[2]}{$str[0]}[0] ) += $str[0]; ( $myhash{$str[2]}{$str[0]}[1] ) += $str[4]; ( $myhash{$str[2]}{$str[0]}[2] ) += $str[5]; ( $myhash{$str[2]}{$str[0]}[3] ) += $str[6]; ( $myhash{$str[2]}{$str[0]}[4] ) += $str[7]; ( $myhash{$str[2]}{$str[0]}[5] ) += $str[8]; ( $myhash{$str[2]}{$str[0]}[6] ) += $str[9]; ( $myhash{$str[2]}{$str[0]}[7] ) += $str[12]; ( $myhash{$str[2]}{$str[0]}[8] ) += $str[13]; ( $myhash{$str[2]}{$str[0]}[9] ) += $str[16]; } else{# if connection type is not stored push(@temp, $str[0], $str[4], $str[5], $str[6], $str[7], +$str[8], $str[9], $str[12], $str[13], $str[16]); $myhash{$str[2]}{$str[0]} = [@temp]; #enter new data } }

    My next step will be determining how to print, I was using the code below but I will change that
    foreach my $element(sort keys %myhash){ printf OUT ("%-20s", $element); foreach (@{$myhash{$element}}){ printf OUT ("%8s", $_); } print OUT "\n"; }#foreach
    thanks everyone