#!/usr/bin/perl -wl use strict; # Map the old client names to the new names my %map = (ABCDEF => 'ABCD', GHIJKJ => 'GHIJ'); # Store the client data in a hash of hash refs my %clients = ( ABCDEF => {name => 'Sam', age => 30}, GHIJKJ => {name => 'Dan', age => 40}, ); # Link the old clients to the data foreach my $key (keys %clients) { $clients{$map{$key}} = $clients{$key}; } # Print the data, modify it and print it again print ${$clients{ABCDEF}}{name}, " is ", ${$clients{ABCDEF}}{age}; print ${$clients{ABCD }}{name}, " is ", ${$clients{ABCD }}{age}; ${$clients{ABCD}}{age} = 35; print ${$clients{ABCDEF}}{name}, " is ", ${$clients{ABCDEF}}{age}; print ${$clients{ABCD }}{name}, " is ", ${$clients{ABCD }}{age}; __END__ Prints: Sam is 30 Sam is 30 Sam is 35 Sam is 35
--
John.
In reply to Re: Multiple keys describing a single hash element
by jmcnamara
in thread Multiple keys describing a single hash element
by Tanalis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |