Some years, months ago I found here on PerlMonks that parentheses are not needed around qw// to create a list for for consumption. Today, I found a failure case listed after working versions ...
#!/usr/local/bin/perl use strict; use warnings; # Working versions. warn $_ for qw/ p / ; for my $var qw/ p / { warn $var } for ( qw/ p / ) { warn $_ } # Fails at compile time. # This is commented just to have the program be compiled and get erro +r via # eval. #for qw/ p / { warn $_ }; my $code = eval "for qw/ p / { warn $_ } " ; warn "code: $code error: $@"; __END__ Error message produced ... Missing $ on loop variable at -e line 1 (#1) ... diagnostics module adds ... (F) Apparently you've been programming in csh too much. Variables + are always mentioned with the $ in Perl, unlike in the shells, whe +re it can vary from one line to the next.
... seems the failing loop is being parsed as for p ( ... ) { ... }.
Perl versions tested were 5.8.7 i686-linux-thread-multi & 5.10.0 i686-linux.
Any comments on if the parentheses lacking versions work by fluke? Or, if the failure is by fluke?
Belatedly added the link to support my fuzzy memory, removed comp.lang.perl.misc reference. Other related discussions ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "for qw/ word / { warn $_ }" fails, other parentheses lacking versions work
by grinder (Bishop) on Apr 04, 2008 at 08:38 UTC | |
by parv (Parson) on Apr 04, 2008 at 11:56 UTC |