Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I have written the following code:
#!/usr/bin/perl -w use strict; my %data=map { "Player number $_", [ map { 1 + int rand(10) } 1 .. 5 ] } 1 .. 10; print "$_ @{$data{$_}}\n" for ( keys %data );
It doesn't work, infact perl prints an error like this:
syntax error at ./mytest line 9, near "} 1" Execution of ./mytest aborted due to compilation errors.
To resolve the problem i have changed this chuck of code:
my %data=map { "Player number $_", [ map { 1 + int rand(10) } 1 .. 5 ] } 1 .. 10;
with this:
my %data=map { "Player number " . $_, [ map { 1 + int rand(10) } 1 .. 5 ] } 1 .. 10;

With the latter chuck of code the little program works and prints an output like this:

Player number6 6 7 3 2 7 Player number2 3 2 6 7 8 Player number7 1 7 3 7 1 Player number1 8 10 4 7 4 Player number10 1 2 5 1 3 Player number9 1 4 10 4 8 Player number4 4 1 4 5 5 Player number3 8 6 9 5 6 Player number5 9 3 5 6 6 Player number8 10 3 8 8 1
Now i am wondering which is the problem with the former code but i am not be
able to find an answer.
Can someone help me to find the right answer?

In reply to syntax error with map in list context by LucaPette

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (8)
    As of 2015-07-29 06:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (260 votes), past polls