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 ...


In reply to "for qw/ word / { warn $_ }" fails, other parentheses lacking versions work by parv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.