shaezi has asked for the wisdom of the Perl Monks concerning the following question:
ab mock 01 data1 data2 data3 data4
ab mock 02 data5 data6 data7 data8
ab mock 03 data9 data0 data3 data2
The third item (from the left) on each line is to be my key for the hash. But then as the value for the hash I want all the values on the line to be associated with that key.
I've tried to split each element on the line into and array and then incorrectly tried to associate that with the hash but obviously that doesn't seem to be working and I don't know how to do it right :). Any help would be appreciated! Another question I would also have is how would I then get a particular array element for a particular key of the hash? Thanks.
here is part of the code:
open(PARMFILE, "<$parmfile") || die "unsuccessful open of input file $ +parmfile"; while (<PARMFILE>) { next if /^#/ || /^\s*$/; chomp; @temp=split(/\s+/,$_); $array_ref = \@temp; # confusion $dbparms{$temp[2]} = $array_ref; # here } close PARMFILE; foreach $item (sort keys %dbparms) { print "$item => $dbparms{$item} \n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(bbfu) (reference to global variable) Re: associate that array with this hash?
by bbfu (Curate) on Sep 27, 2001 at 20:00 UTC | |
by shaezi (Acolyte) on Sep 27, 2001 at 20:09 UTC | |
by bbfu (Curate) on Sep 27, 2001 at 20:11 UTC | |
by shaezi (Acolyte) on Sep 27, 2001 at 20:23 UTC | |
by bbfu (Curate) on Sep 27, 2001 at 20:29 UTC | |
|
Re: associate that array with this hash?
by davorg (Chancellor) on Sep 27, 2001 at 20:11 UTC |