Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: easy way to get random key from hash?

by jsprat (Curate)
on Aug 05, 2002 at 19:53 UTC ( [id://187797]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my ($i, $jokekey);
    ++$i && rand($i) < 1 && ($jokekey = $_) for (keys %hash);
    
  2. or download this
    sub choose {
      #assumes 1st param is \%knockknocks
      my $jokeref = shift;
      my @setups = keys %$jokeref;
      return $setups[rand @setups];
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found