Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hash converting to hash 1

Status
Not open for further replies.

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 => (y)

Can somebody help me? Thanx

Robert
 
somebody have some tips,...
 
What code did you use to construct the initial hash? I would think this task would be pretty similar to that.
 
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;
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top