On 3/18/07, Darren Duncan wrote:
On Sun, 18 Mar 2007, Aaron Crane wrote:
> That's easy even in Perl 5. This modifies %hash in-place:
> my @values = delete @[EMAIL PROTECTED];
> @[EMAIL PROTECTED] = @values;
If %hash contained keys a,b,c and @old_names was a and @new_names
was b, then the above code would overwrite the existing b element,
and leave 2 elements total. The operation I proposed needs to fail
when one requests a colliding element, such as that situation; [...]
Yes, and more than that, deleting an old key and adding a new one
isn't strictly the same as renaming a key. Consider what would
happen if the value were a funny object that had side-effects every
time you evaluated it.
As for the name, I don't think it's a problem for hashes and IOs to
both have "rename" methods, but I do like Uri's "rekey" suggestion.