BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
Why is the following snippet producing a 'syntax error'?
perl -Mstrict -wle"my %x = map{ 'A' => $_ } 1 .. 10" syntax error at -e line 1, near "} 1" Execution of -e aborted due to compilation errors.
Note: I know it may not be logical to assign one key, 10 different values one after the other, but a syntax error?
Note also that both of these are legal:
perl -Mstrict -wle"my %x = map{ $_ => $_ } 1 .. 10" perl -Mstrict -wle"my %x = map{ 'A' . $_ => $_ } 1 .. 10"
But this also isn't "legal syntax" (regardless of whether you use qq// or ""), even though it is logical.
P:\test>perl -Mstrict -wle"my %x = map{ qq[A_$_] => $_ } 1 .. 10" syntax error at -e line 1, near "} 1" Execution of -e aborted due to compilation errors.
So this isn't just a case of over-zealous code policing?
It woudn't be quite so bad if it didn't point you at the wrong part of the statement as the source of the error.
Perl 5.8.4 (AS810).
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Mysterious "syntax error"
by merlyn (Sage) on Nov 30, 2004 at 15:52 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2004 at 16:07 UTC | |
by dragonchild (Archbishop) on Nov 30, 2004 at 18:12 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2004 at 22:48 UTC | |
by tye (Sage) on Dec 01, 2004 at 00:20 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2004 at 01:22 UTC | |
by merlyn (Sage) on Nov 30, 2004 at 22:10 UTC | |
Re: Mysterious "syntax error"
by bart (Canon) on Nov 30, 2004 at 15:52 UTC | |
Re: Mysterious "syntax error"
by duff (Parson) on Nov 30, 2004 at 15:54 UTC |