1 #!/usr/bin/perl 2 use strict; 3 use Data::Dumper; 4 my @oldfields = qw/old_foo old_bar old_baz/; 5 my @newfields = qw/foo bar baz/; 6 7 my $hashref = { old_foo => 'aaa', old_bar => 'bbb', old_baz => 'ccc' }; 8 9 $hashref->{new_values} = { map { "new_$_" => $hashref->{"old_$_"} } @newfields }; 10 # $details->{company_address} = { map { "addr_$_" => $details->{"comp_addr_$_"} } qw/postal_address post_code country phone_no fax _no mobile_no/ }; 11 12 print "data structure : \n", Dumper(%$hashref), "\n";seems to upset perls compiler (versions 5.6 and 5.8.0) which is a shame as I planned to munge a load of data this way.
perl gives the error message :
syntax error at hashrefslice.pl line 9, near "} @newfields "
richardc seems to agree somethings not right..
is there something we missed ? perhaps there is a more elegant way that works.
Note the extra parens.map { ("new_$_" => $hashref->{"old_$_"}) } @newfields
Re:You've just confused the parse
rafael on 2003-05-16T14:26:07
And that's even documented in perlfunc/map.Re:You've just confused the parse
TeeJay on 2003-05-16T15:07:09
I wasn't sure it was a bug in perl - hence the journal entry..Like I said - There had a to be an elegant way of doing it and in the end I just simplified it so that it no longer used "old_$_" but $_ and ItJustWorked(TM).