Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
Semi-idle question -- I have a comma-sparated list of things whose length is unknown, but is at least one:
apple apple,banana,cherry banana,cherry apple,cherry banana cherry
And I have to pick one at random. Obviously if there's just one, we pick that one.
I did it like this:
@sections = split( ',', $_ ); print "CHOSEN: ", $sections[ int( rand(@sections) ) ], "\n";
Is there a way to do it more succinctly without creating that temporary array?
Back to
Seekers of Perl Wisdom