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

Paul Makepeace paulm at paulm.com
Wed Mar 28 13:36:31 BST 2007


On 3/27/07, Joel Bernstein <joel at fysh.org> 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 }'
> a
> b

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

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


> jbernstein at bandicoot 11:57 ~ $ perl -le 'for qw(a b) { print }'
> Missing $ on loop variable at -e line 1.
> zsh: exit 255   /usr/bin/perl -le 'for qw(a b) { print }'
> jbernstein at bandicoot 11:57 ~ $ perl -v
> This is perl, v5.8.6 built for darwin-thread-multi-2level
>
> HTH,
>
> /joel
>


More information about the london.pm mailing list