I almost got it figured out. It's not an in-place transformation, as I was hoping to create. Actually, I was hoping to invent the Roboticus transform, but this'll have to do! ;^)
When run on my box, it gives:#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; # original hash my $h = { mm => 'July', yyyy => '1975', dd => '31', name => 'Milo', last_name => 'Manara', }; print Dumper($h); my $x = { mm=>'month', dd=>'day', yyyy=>'year' }; my $t; @$t{map{$$x{$_}||$_}keys %$h) = values %$h; print Dumper($t);
NBKI44V@B000F1FA4379F /Work/Tools/DataMap $ ./rehash2.pl $VAR1 = { 'mm' => 'July', 'name' => 'Milo', 'dd' => '31', 'last_name' => 'Manara', 'yyyy' => '1975' }; $VAR1 = { 'month' => 'July', 'day' => '31', 'name' => 'Milo', 'year' => '1975', 'last_name' => 'Manara' };
Update:Drat! While experimenting and composing this response, several enterprising perl monks found several much better solutions.
...roboticus
In reply to Re: can i rename hashref keys?
by roboticus
in thread can i rename hashref keys?
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |