Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TeeJay (2309)

  (email not shown publicly)

Working in Truro
Graduate with BSc (Hons) in Computer Systems and Networks
pm :,,
lug : Devon & Cornwall LUG
irc : TeeJay
skype : hashbangperl
livejournal : hashbangperl []
flickr :hashbangperl []

Journal of TeeJay (2309)

Friday May 16, 2003
08:37 AM

bug in perl ?

[ #12248 ]

      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/;
      7 my $hashref = { old_foo => 'aaa', old_bar => 'bbb', old_baz => 'ccc' };
      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/ };
     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 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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • map { ("new_$_" => $hashref->{"old_$_"}) } @newfields
    Note the extra parens.

    It's still weird though.
      ---ict / Spoon
  • by Elian (119) on 2003.05.16 9:20 (#20192) Homepage Journal
    The potential meaning of { is so overloaded that perl has to do some probabalistic analysis to figure out what you mean when you put a { in--is it the left bracket for a block, a hash index, or an anonymous hash constructor? (There's some interesting code that calculates a weighted score based on surrounding constructs, and decides based on that) All that's happened is that your code has, in a mildly ambiguous circumstance, gone down the wrong path. Dunno if I'd call this a bug in perl, since the offending line can certainly be interpreted in several ways.

    Short answer: You're being Too Damn Clever and confused the parser. Stop that.