Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 119162
Status: open
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: NEILB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.46
Fixed in: (no value)



Subject: Proposed new function: lucky_dip (randomly selected item from list)
Hi, I've used shuffle in a number of places, and just now wanted to select one item at random from a list. my @messages = ( "Well done!", "Awesome job", "Idiot!" ); my $message = pick @messages; you could add a parameter, so pick($n, @messages), which also addresses RT#105275 This is a trivial thing to do, but I was sure there would be a function for this in List::Util. Turns out there isn't. Was trying to think of a short and obvious name, like "pick", or "lucky_dip", but haven't yet come up with one that feels dead right. "pick" seems to match the existing terse naming, but "lucky_dip" more obviously identifies the function. Submitting as a separate ticket as the "lucky_dip" function would be best as: my $message = lucky_dip @messages; But pick would probably be best as: my ($message) = pick 1, @messages;
This can likely be handled by 1.54's "sample" my ($item) = sample 1, @list; -- Paul Evans
Cool. In your next release, maybe add sample() to SYNOPSIS? :-)