in reply to Re^2: can i rename hashref keys?
in thread can i rename hashref keys?

Given that delete can delete a slice, this can be simplified:

my %map = (...); @$h{values %map} = delete @$h{keys %map};

Update: note that this doesn't break on %map = (foo => 'bar', bar => 'foo') that the solutions above may do.

lodin

Replies are listed 'Best First'.
Re^4: can i rename hashref keys? (...simplified)
by tye (Sage) on Nov 29, 2007 at 17:42 UTC

    Given that initializing the hash just requires you list a bunch of keys and values, this can be simplified:

    @{$h}{qw/ month year day first_name /}= delete # New keys @{$h}{qw/ mm yyyy dd name /}; # Old keys

    Yeah, I added some extra braces.

    - tye