Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl Tutorial code uses "qw" but has an error when run

by 1nickt (Canon)
on May 02, 2018 at 14:52 UTC ( [id://1213947]=note: print w/replies, xml ) Need Help??


in reply to Perl Tutorial code uses "qw" but has an error when run

If you want to loop through the list with for you'll still have to use parens around the list that qw generates.

$ perl -wE 'for my $d qw^ 2006-10-21 15.01.2007 10/31/2005 ^ { say $d +}' syntax error at -e line 1, near "$d qw^ 2006-10-21 15.01.2007 10/31/20 +05 ^" Execution of -e aborted due to compilation errors. $ perl -wE 'for my $d (qw^ 2006-10-21 15.01.2007 10/31/2005 ^) { say $ +d } ' 2006-10-21 15.01.2007 10/31/2005
Note that I am using ^ for the qw delimiter to disambiguate from the list parens.

Also note that you don't need the list parens if using a postfix for:

$ perl -wE 'say $_ for qw^ 2006-10-21 15.01.2007 10/31/2005 ^' 2006-10-21 15.01.2007 10/31/2005

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found