Nicole Seitz wrote: > hi there! > > I've got a problem with a complex data structure and hope you can > help me. > > I know that I can't have a hash whose values are arrays. So I tried > to build a hash of references to arrays. > > I guess I've made some mistakes . > > This is what my hash looks like: > > %myHash = (); > # lots of code here > $myHash{"245"} = [[$len245oa,$pos,$tag245oa]]; > #some code here > > $myHash{"856"} = [[$len856_41,$pos,$tag856_41]]; > #some code here > #now I have to add a new element(which is also an array) to the outer > anonymous array > #Is the following correct? > $myHash{"856"}[1] = [$len856_42,$pos,$tag856_42]; > > > #Then I'd like to iterate over the array of sorted hash keys(no > problem) > > @sortedKeys = sort keys %myHash; > foreach $key (@sortedKeys) { > # now I have to change the value of each second element of the inner > arrays($myHash{$key} [$index][1] ???) > #Unfortunately, I don't know how to do this. I guess, first, I need > another loop.But then how to access the second element and overwrite > it??? > > > Many thanx in advance. > > > Nicole
Here is one possible way: my %MyHash = (); push (@{$MyHash{'245'}}, 10,15,20 ); # just picked some numbers, but pushing on the hash # easier way of generating your array within your hash foreach $MyKey (keys %MyHash) { my $MyMax = scalar(@{$MyHash{$MyKey}}); printf "%4s : ", $MyKey; for(my $MyId=0;$MyId<$MyMax;$MyId++) { printf "%4d ", $MyHash{$MyKey}[$MyId]; } printf "\n"; } I believe this is the way, though if not the true gurus of the list will show us the right way. To update element 2: $MyHash{$MyKey}[2] = new value; Wags ;) ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]