On Sun, 18 Mar 2007, Aaron Crane wrote:
> David Green writes:
> > In the meantime, Darren's proposal still raises a lot of interesting
> > language questions.  For example, how *do* you rename a hash key?
> 
> That's easy even in Perl 5.  This modifies %hash in-place:
> 
>   my @values = delete @[EMAIL PROTECTED];
>   @[EMAIL PROTECTED] = @values;
> 
> While there's certainly motivation to wrap this up in a function or
> operator, it doesn't strike me as something particularly difficult, or
> necessarily more worthy of inclusion in Perl 6.0.0 than anything else.

Actually, what I proposed is more complicated than that.  Any key-renames 
such as I propose need to be non-colliding.  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; a successful operation will leave a Hash that is 
identical but for the element key changes; there would be the same number 
of elements and they have the same values.  So if a short-hand syntax 
existed, it would be replacing more complicated code than that. -- Darren 
Duncan

Reply via email to