Oct 5, 2006 #1 ncmls Programmer Joined Oct 5, 2006 Messages 2 Location NL Hi, I've got a problem: I wanna covert this hash x => (a , b) y => (a , c) z => (a) to a hash like this a => (x, y, z) b => (x) c => Can somebody help me? Thanx Robert
Hi, I've got a problem: I wanna covert this hash x => (a , b) y => (a , c) z => (a) to a hash like this a => (x, y, z) b => (x) c => Can somebody help me? Thanx Robert
Oct 5, 2006 Thread starter #2 ncmls Programmer Joined Oct 5, 2006 Messages 2 Location NL somebody have some tips,... Upvote 0 Downvote
Oct 5, 2006 #3 ishnid Programmer Joined Aug 29, 2003 Messages 1,422 Location IE What code did you use to construct the initial hash? I would think this task would be pretty similar to that. Upvote 0 Downvote
What code did you use to construct the initial hash? I would think this task would be pretty similar to that.
Oct 5, 2006 1 #4 rharsh Technical User Joined Apr 2, 2004 Messages 960 Location US See if this helps: Code: my %hash = ( x => [qw/a b/], y => [qw/a c/], z => [qw/a/] ); my %hash1; foreach my $key (keys %hash) { foreach my $value (@{ $hash{$key} }) { push @{ $hash1{$value} }, $key; } } Upvote 0 Downvote
See if this helps: Code: my %hash = ( x => [qw/a b/], y => [qw/a c/], z => [qw/a/] ); my %hash1; foreach my $key (keys %hash) { foreach my $value (@{ $hash{$key} }) { push @{ $hash1{$value} }, $key; } }