in reply to Re: How can I delete a key' value from a hash
in thread How can I delete a key' value from a hash
printf "Before deleting: city= %s state=%s zip= %s\n", $city , $location_hash->{ $city }->{ 'ST' }, $location_hash->{ $city }->{ 'ZIP' }; delete ($location_hash->{ $city }); delete ($location_hash->{ $city }->{ 'ST' }) ; delete ($location_hash->{ $city }->{ 'ZIP' }) ; printf "After deleting: city= %s state=%s zip= %s\n", $city, $location_hash->{ $city }->{ 'ST' }, $location_hash->{ $city }->{ 'ZIP' };
Ok, I feel like an idiot ... lol It kept printing $city because it was NOT in the hash. $city was declared above. I almost did not admit it but I wanted you all to get a good laugh :) new code:Before deleting: city= Lucketts state=VA zip= 20176 After deleting: city= Lucketts state= zip=
Output:for my $city ( keys %$location_hash ) { . . . printf "Before deleting: state=%s zip= %s\n", $location_hash->{ $city }->{ 'ST' }, $location_hash->{ $city }->{ 'ZIP' }; delete ($location_hash->{ $city }); ### delete ($location_hash->{ $city }->{ 'ST' }) ; ### delete ($location_hash->{ $city }->{ 'ZIP' }) ; printf "After deleting: state=%s zip= %s\n", $location_hash->{ $city }->{ 'ST' }, $location_hash->{ $city }->{ 'ZIP' }; } end for loop
Everyone, thanks for your help. Sometimes it helps to have someone to talk to about it and as you explain it you think, "Dah."Before deleting: state=VA zip= 20176 After deleting: state= zip= Before deleting: state=VA zip= 20176 After deleting: state= zip=
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How can I delete a key' value from a hash
by Animator (Hermit) on Jan 08, 2007 at 12:16 UTC |