anadem has asked for the wisdom of the Perl Monks concerning the following question:
when stored it should be something like this:item 1 # as read from file $key = "k1"; $valname = "vname1"; $value = "v1"; $type = "t1"; $flag = "f1"; $hash{ $key } = ( { $valname => [ $value, $type, $flag ] }); item 2 $key = "k1"; $valname = "vname2"; $value = "v2"; $type = "t2"; $flag = "f2"; $hash{ $key } = ( { $valname => [ $value, $type, $flag ] }); item 3 $key = "k3"; $valname = "vname3"; $value = "v3"; $type = "t3"; $flag = "f3"; $hash{ $key } = ( { $valname => [ $value, $type, $flag ] }); item N (indeterminate until runtime)
Note that both items 1 and 2 have the same value for $key. My attempt at storing the data is wrong, so item2 overwrites item1 and k1's inner (anonymous) hash has only item2's data.k1 => vname1 => (v1, t1, f1) vname2 => ( v2, t2, f2 ) k3 => vname3 => ( v3, t3, f3 )
The loop to access the data isn't good either -- somewhere the perl's too slippery for me -- so any hints or even better solutions would be wonderful.foreach $i (keys %hash) { print "i=$i\n"; foreach $j (keys %{$hash{$i}} ) { @content = $hash{$i}->{$j}; #print "\tvalname=$j content=$$hash{$i}->{$j}[1] \n"; print "\tj=$j val=$hash{$i}->{$j}[0] type=$hash{$i}->{$j}[1] +flag=$hash{$i}->{$j}[2] \n"; print "$content[0] $content[1] $content[2]\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inner anonymous hash
by friedo (Prior) on Feb 13, 2005 at 07:01 UTC | |
|
Re: inner anonymous hash
by injunjoel (Priest) on Feb 13, 2005 at 10:11 UTC | |
|
Re: inner anonymous hash
by bobf (Monsignor) on Feb 13, 2005 at 19:17 UTC | |
|
Re: inner anonymous hash
by brian_d_foy (Abbot) on Feb 13, 2005 at 18:53 UTC | |
|
Re: inner anonymous hash
by anadem (Scribe) on Feb 14, 2005 at 16:46 UTC |