Search code examples
perl

How to generate an array with random values, without using a loop?


How can I generate an array in Perl with 100 random values, without using a loop?

I have to avoid all kind of loops, like "for", foreach", while. This is my exercise, from my lab. I can't find a way to do solve this, because I am new in Perl.

In C, generating this array would by very easy, but I don't know how to do it in Perl.


Solution

  • my @rand = map { rand } ( 1..100 );
    

    But a map is just a loop with fancy window-dressing.

    If you need to do something 100 times, you're going to need to use some kind of iterative structure.