Hi Nicole "Nicole Seitz" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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 . >
Not many: you're very close :) > > This is what my hash looks like: > > %myHash = (); > # lots of code here my %myHash; You _do_ have 'use strict' :-? > $myHash{"245"} = [[$len245oa,$pos,$tag245oa]]; > #some code here > > $myHash{"856"} = [[$len856_41,$pos,$tag856_41]]; > #some code here Fine so far, but it would be more straightforward like this: push @{$myHash{245}}, [$len245oa,$pos,$tag245oa]; push @{$myHash{856}}, [$len856_41,$pos,$tag856_41]; Note that you don't in general need quotes around a hash key. > #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]; > Yes, but you could just carry on as before: push @{$myHash{856}}, [$len856_42,$pos,$tag856_42]; Using 'push' you don't have to work out the index of the next array element to insert. > > #Then I'd like to iterate over the array of sorted hash keys(no problem) > > @sortedKeys = sort keys %myHash; > foreach $key (@sortedKeys) { There's no need to store the sorted list: foreach $key (sort keys %myHash) > # 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??? Yes, you could put in another loop: for ( $index = 0; $index < @{$myHash{$key}}; $index++ ) { print $myHash{$key}[$index][1], "\n"; } but more simply, just: foreach $item ( @{$myHash{$key}} ) { print $item->[1], "\n"; # or $$item[1] } > > > Many thanx in advance. > Welcome. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]