LucaPette has asked for the wisdom of the Perl Monks concerning the following question:
I have written the following code:
able to find an answer.
Can someone help me to find the right answer?
It doesn't work, infact perl prints an error like this:#!/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 );
To resolve the problem i have changed this chuck of code:syntax error at ./mytest line 9, near "} 1" Execution of ./mytest aborted due to compilation errors.
with this:my %data=map { "Player number $_", [ map { 1 + int rand(10) } 1 .. 5 ] } 1 .. 10;
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:
Now i am wondering which is the problem with the former code but i am not bePlayer 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
able to find an answer.
Can someone help me to find the right answer?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: syntax error with map in list context
by dave0 (Friar) on Nov 20, 2005 at 13:38 UTC | |
Re: syntax error with map in list context
by Aristotle (Chancellor) on Nov 20, 2005 at 17:52 UTC | |
Re: syntax error with map in list context
by pg (Canon) on Nov 20, 2005 at 17:26 UTC | |
Re: syntax error with map in list context
by davidrw (Prior) on Nov 20, 2005 at 12:48 UTC |
Back to
Seekers of Perl Wisdom