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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
One of the few changes in Perl syntax now requires parentheses around all lists.
When did that happen? Why would p5p give us one less way to do things while breaking an unknown number of CPAN modules? What's the point?

As others explained, it happened more or less in v5.14.0. And the cited statement "now requires parentheses around all lists" is unfortunately wrong.

To make a long story short, you now have to have parentheses where they were always required by the documentation. A parser bug allowed to omit them sometimes. You don't have to wrap all lists in parentheses. In places like use, parentheses around lists are not required and were never required.

For the details, read on.

From perldelta5140:

Use of qw(...) as parentheses

Historically the parser fooled itself into thinking that qw(...) literals were always enclosed in parentheses, and as a result you could sometimes omit parentheses around them:

for $x qw(a b c) { ... }

The parser no longer lies to itself in this way. Wrap the list literal in parentheses like this:

for $x (qw(a b c)) { ... }

This is being deprecated because the parentheses in for $i (1,2,3) { ... } are not part of expression syntax. They are part of the statement syntax, with the for statement wanting literal parentheses. The synthetic parentheses that a qw expression acquired were only intended to be treated as part of expression syntax.

Note that this does not change the behaviour of cases like:

use POSIX qw(setlocale localeconv); our @EXPORT = qw(foo bar baz);

where parentheses were never required around the expression.

It was a bug in the parser. qw( ... ) was wrongly parsed as (qw( ... )), and so code that omitted the parentheses was wrongly accepted as valid perl code. In 2011 / v5.14.0, using the bug was deprecated. Code that was always wrong is still wrong, and now caused warnings (see "Use of qw(...) as parentheses" in perldelta5140).

In 2012 / v5.17.0, the bug was finally fixed in the development version and caused an error (see perldelta5170). The same happened two years later, in 2013 in the stable version v5.18.0 (see perldelta5180). The parser no longer hallucinates the extra parentheses. Code that was always wrong is still wrong, but now correctly generates a syntax error complaining about missing parentheses.

Quoting perldelta5180:

qw(...) can no longer be used as parentheses

qw lists used to fool the parser into thinking they were always surrounded by parentheses. This permitted some surprising constructions such as foreach $x qw(a b c) {...}, which should really be written foreach $x (qw(a b c)) {...}. These would sometimes get the lexer into the wrong state, so they didn't fully work, and the similar foreach qw(a b c) {...} that one might expect to be permitted never worked at all.

This side effect of qw has now been abolished. It has been deprecated since Perl v5.13.11. It is now necessary to use real parentheses everywhere that the grammar calls for them.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^3: How can I create a simple Autocad drawing with Perl by afoken
in thread How can I create a simple Autocad drawing with Perl by Lotus1

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-03-28 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found