in reply to Re: oneliner for selecting multiple values from array
in thread oneliner for selecting multiple values from array
A little more generally you could:
which will give you any length string you like.my @arr = ('A'..'Z'); my $n = 2 ; my $combo = join '', map { $arr[rand @arr] } (1..$n) ; print $combo . "\n";
Whatever you do, don't do:
however plausible it might appear :-(my @arr = ('A'..'Z'); my $n = 2 ; my $combo = $arr[rand @arr] x $n ; print $combo . "\n";
Of course it doesn't work, you say, it's obvious... However, I have, ahem, a friend who once (once was enough):
and had a lot of fun (tm) working out why their program behaved as oddly as it did !my @arr = ([]) x $count ;
|
|---|