Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: How can I create a simple Autocad drawing with Perl

by afoken (Canon)
on Sep 29, 2019 at 19:26 UTC ( #11106846=note: print w/replies, xml ) Need Help??


in reply to Re^2: How can I create a simple Autocad drawing with Perl
in thread How can I create a simple Autocad drawing with Perl

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". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-01-25 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?