Hello oh wise monks,
I am trying to construct a Hash of an Array and frankly I am making a Hash of it. This is what I am trying to achieve
Fields 5 onwards are not needed for this process. Field 4 is what I want to use for the key, but is not unique. Field 1 is then going to be used to populate the array in the hash and is unique for each line. The first part of the code, to create the empty hash is done like this:# Comments - To be ignored field 1 ;field 2 ;field 3 ;field 4 ;field 5; field 6;
This seems to workwhile (<FILE>) { chomp; if ($_ !~ m/#/) { s/\t//g; s/\s//g; ($f1,$f2,$f3,$f4,$f5) = split (/;/, $_,5); push @file,$_; unless ($seen{$f4}) { $seen{$f4}=1; $mailhouse{$f4} = ""; } } }
This is the part that does not work.for $mh ( keys %mailhouse ) { foreach (@file) { ($g1,$g2,$g3,$g4,$g5) = split (/;/, $_,5); if ($mh eq $g4) { push @{ $mailhouse{$mh} }, $g1; } } }
What seems to happen is once the field 1 is pushed into the array, it seems to populate for all the keys of the hash.
Can anyone point me in the right direction? Can anyone suggest an alternative?
Cheers, the hoff
In reply to A Hash that is giving me the ####s by hoffy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |