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.
It works with more parens (Score:1)
It's still weird though.
---ict / Spoon
You've just confused the parse (Score:3, Informative)
Short answer: You're being Too Damn Clever and confused the parser. Stop that.
Reply to This
Re:You've just confused the parse (Score:3, Informative)
Re:You've just confused the parse (Score:2)
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).
@JAPH = qw(Hacker Perl Another Just);
print reverse @JAPH;