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)
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.18-22725-1481105733-1690.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 926
Download (untitled) / with headers
text/plain 926b
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;
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-22725-1481105733-1690.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-22725-1481105733-1690.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-22481-1580950299-1994.119162-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 95
This can likely be handled by 1.54's "sample" my ($item) = sample 1, @list; -- Paul Evans
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-22481-1580950299-1994.119162-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-22725-1481105733-1690.0-0-0 [...] rt.cpan.org> <rt-4.0.18-22481-1580950299-1994.119162-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-4864-1580984275-1548.119162-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 65
Cool. In your next release, maybe add sample() to SYNOPSIS? :-)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.