New(?) for qw(...) error

Uri Guttman uri at
Wed Mar 28 21:14:42 BST 2007

>>>>> "PM" == Paul Makepeace <paulm at> writes:

  PM> On 3/27/07, Joel Bernstein <joel at> wrote:
  >> On Tue, Mar 27, 2007 at 11:10:57AM +0100, Paul Makepeace wrote:
  >> > I've just had one of my dodgier scripts start bailing on this construction,
  >> >
  >> > $ perl -le 'for $a qw(a b) { print $a }'
  >> > a
  >> > b
  >> > $ perl -le 'for qw(a b) { print }'
  >> > Missing $ on loop variable at -e line 1.
  >> >
  >> > This is on 5.8.8; not sure when this kicked in.
  >> So put the brackets back!
  >> jbernstein at bandicoot 11:57 ~ $ perl -le 'for (qw(a b)) { print }'

  PM> Recent-ish perls don't need the brackets. But yeah, I know how to fix
  PM> it, personally chosing 'for my $f qw(a b)'; I just thought it was
  PM> interesting that this problem (apparently) only just started
  PM> manifesting itself and appeared to be perl misparsing the 'a' as a
  PM> variable without a $.

what recentish perls are you referring to? perl6 doesn't count and all
perl5s need parens around the for list. only the for modifier doesn't
need parens and it never has. maybe you conflated those two?

  PM> I'm puzzled by people's reports that this error comes up even for old
  PM> perls; this script's been working for years and only more recently
  PM> after a server move started 500ing (the old server was debian testing
  PM> and reasonably current). Ah well, *shurg*

i find that hard to believe. but there is one possibility that i ran
into a couple of years ago. qw changed from a run time operation (it
called split ' ' on the string and returned it) to a compile time parsed
which builds a list of strings. this change (i think it was 5.6 or so)
caused bugs in this large pile of doodoo code which had modified a qw
list in place. with the old runtime split this worked fine as the
strings were in an expression and read/write. with the newer perl the
strings were now tokens or constants and couldn't be modified. maybe
this is the cause? i don't see how this would affect the lack of
parens/syntax but it was a major change in how qw is implemented.


Uri Guttman  ------  uri at  --------
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------

More information about the mailing list