Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: syntax error with map in list context

by dave0 (Friar)
on Nov 20, 2005 at 13:38 UTC ( [id://510244]=note: print w/replies, xml ) Need Help??


in reply to syntax error with map in list context

It's a known issue with Perl guessing wrong on the meaning of the initial {. See the Perldoc for map, in the paragraph beginning:

"{" starts both hash references and blocks, so "map { ..." could be either the start of map BLOCK LIST or map EXPR, LIST.

There are examples of how to avoid the problem in that doc, but my suggestion would be:

my %data = map +( "Player number $_" => [ map { 1 + int rand(10) } 1 .. 5 ] ), 1 .. 10;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-09-17 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.