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

McGlinchy, Alistair Alistair.McGlinchy at marks-and-spencer.com
Wed Mar 28 14:06:13 BST 2007


Dirk Koopman wrote:
> 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.
> > 
> > P
> 
> $ perl -le 'for (qw(a b)) { print }'
> a
> b

While verifing this little meme, I found this extra piece of magical $_
fun.  Shouldn't these all print the same thing?

%  perl -le 'for $_  (qw(a b)) { print    }'
a
b
%  perl -le 'for $_   qw(a b)  { print    }'   
%
%  perl -le 'for $_   qw(a b)  { print $_ }'
a
b


Cheers

Alistair

**********************************************************************
Registered Office:
Marks and Spencer plc
Waterside House
35 North Wharf Road
London
W2 1NW

Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422
Facsimile (020) 7487 2670

<<www.marksandspencer.com>>

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.
2005





More information about the london.pm mailing list