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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change hash key name? 3

Status
Not open for further replies.

al0

Technical User
Apr 30, 2006
6
SE
Hi,

Is it possible to change a keyname in a hash? My keys values in the hash references to arrays. I have a option in my script where you can change the information in the hash.
Code:
chomp($hash{$matching_keys[$val]}[0]=<STDIN>);
chomp($hash{$matching_keys[$val]}[1]=<STDIN>);
chomp($hash{$matching_keys[$val]}[2]=<STDIN>);
After I have changed the values in the array inside my hash I want to change the keyname "$hash{$matching_keys[$val]" to something else.
 
You can't rename it, as such, but you can copy the value to another hash key and remove the first one, which has the same effect.

Code:
$hash{new_keyname = $hash{$matching_keys[$val]};
delete $hash{$matching_keys[$val]};
 
Thanks a lot, have been struggling with this for quite a bit of time.
 
You're welcome. Actually, there's a closing brace missing in the above code. Just to correct it, it should be:
Code:
$hash{new_keyname} = $hash{$matching_keys[$val]};
delete $hash{$matching_keys[$val]};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top