Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Select randomly from a hash

by Enlil (Parson)
on Oct 16, 2004 at 22:44 UTC ( #399841=note: print w/ replies, xml ) Need Help??


in reply to Select randomly from a hash

Hashes require an even amount of elements. The first of each pair is the key and the second is that key's value. So warnings would tell you your %verbs hash contains an odd amount of elements. Take a look at perldata. I think what you are looking for are simple arrays, and getting random combinations of two arrays via rand. Something like this should work:

use strict; use warnings; my @pronouns = qw/He She I Me/; my @verbs = qw /jumped ate laughed cheated/; print $pronouns[rand @pronouns] . ' ' . $verbs[rand @verbs] . $/;

-enlil


Comment on Re: Select randomly from a hash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2015-07-28 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls