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

后端 未结 24 2162
逝去的感伤
逝去的感伤 2020-12-13 19:23

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 exerc

24条回答
  •  情话喂你
    2020-12-13 19:57

    While the copy'n'paste examples are novel and the map/foreach alternatives have also been mentioned, I think one approach that has not been discussed is recursion. Using recursion (an implicit loop) would need method calls and a simple 'if' statement: no for/grep/map/etc. It could be side-effecting or side-effect free.

    Since this is homework, I will leave the implementation to the poster.

    Happy coding.

    BTW: Nobody has posted a regular expression solution yet ;-)

    It's nice to see some even more innovative solutions! :-)

提交回复
热议问题