in reply to strange syntax error with map
From map:
{ starts both hash references and blocks, so map { ... could be either the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look ahead for the closing } it has to take a guess at which it's dealing with based on what it finds just after the {. Usually it gets it right, but if it doesn't it won't realize something is wrong until it gets to the } and encounters the missing (or unexpected) comma. The syntax error will be reported close to the }, but you'll need to change something near the { such as using a unary + or semicolon to give Perl some help:
$ perl -wMstrict -le 'print map { (2, $_) } 1 .. 2' 2122 $ perl -wMstrict -le 'print map {; 2, $_ } 1 .. 2' 2122 $ perl -wMstrict -le 'print map { +2, $_ } 1 .. 2' 2122
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: strange syntax error with map (unary plus)
by LanX (Saint) on Apr 09, 2017 at 13:52 UTC | |
by haukex (Archbishop) on Apr 09, 2017 at 17:48 UTC | |
|
Re^2: strange syntax error with map
by BillKSmith (Monsignor) on Apr 09, 2017 at 13:30 UTC | |
by ikegami (Patriarch) on Apr 10, 2017 at 16:00 UTC | |
by BillKSmith (Monsignor) on Apr 10, 2017 at 19:05 UTC | |
by rsFalse (Chaplain) on Apr 12, 2017 at 23:32 UTC | |
|
Re^2: strange syntax error with map
by rsFalse (Chaplain) on Apr 09, 2017 at 11:47 UTC |