Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: [closed] map sentence as array slice indexes

by Discipulus (Canon)
on Nov 25, 2015 at 12:09 UTC ( [id://1148598]=note: print w/replies, xml ) Need Help??


in reply to [closed] map sentence as array slice indexes

Hello,
in the docs for map i read:
{ 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:
So you need to help Perl doing the right guess, using a plus sign (and parentheses!):
use warnings; use strict; @_ = 'a' .. 'c'; print @_[ map +($_ -1), grep { $_ > 0 and $_ <= 1 } map { $_ + 1 } -1..1 ];

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found