ambrus has asked for the wisdom of the Perl Monks concerning the following question:
The expression print qw/foo bar/ x 5 results in a syntax error. Here's the exact messages I get:
[am]king ~/a$ perl -wle 'print qw/foo bar/ x 5;' Unquoted string "x" may clash with future reserved word at -e line 1. Number found where operator expected at -e line 1, near "x 5" (Do you need to predeclare x?) syntax error at -e line 1, near "qw/foo bar/ x " Execution of -e aborted due to compilation errors. 255[am]king ~/a$ perl -v This is perl, v5.8.5 built for i686-linux Copyright...
I'm not sure what semantics this expression should have. It could be list repetition, like print((qw/foo bar/) x 5), or string repetition like print(scalar((qw/foo bar/) x 5)). I could imagine either: string repetition because the lhs of the x operator is not explicitly parenthisezed, or list repetition because perl treats qw as a parenthisized expression in print(qw/foo bar/[1]), and it is in list context here. However, I wouldn't have expected the current behaiviour: a (compile-time) syntax error.
So, all-knowing monks, I ask you to please explain me why this is a syntax error.
Update: I fixed a typo noticed by kutsu and others, where I had perl instead of print at one place.
Update: print qw/3 7/ - 5; is a syntax error too.
Update: ysth has kindly informed me in the CB that this has changed in bleadperl, and referred me to this perlbug discussion on it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: repetition of qw: syntax error
by ysth (Canon) on Jun 22, 2005 at 21:35 UTC | |
|
Re: repetition of qw: syntax error
by QM (Parson) on Jun 22, 2005 at 21:29 UTC | |
|
Re: repetition of qw: syntax error
by graff (Chancellor) on Jun 23, 2005 at 02:13 UTC | |
by ysth (Canon) on Jun 23, 2005 at 08:16 UTC |