in reply to selecting random key from hash
Long time listener, first time poster.
Not sure about effiency - I'm just always looking for an excuse to use a psuedo :-)
Consider the following:
$rnd_phash = [ {black=>1, green=>2, blue=>3, yellow=>4, red=>5, purple=>6}, 'black door', 'green grass', 'blue devil', 'yellow belly', 'red ro +ses', 'purple grape' ]; # array in psuedo hash is 1 relative not 0 relative $i = int rand $#{$rnd_phash} +1; print "Random hash element: $$rnd_phash[$i]\n"; print "The value of \$\$rnd_phash{red} is $$rnd_phash{red}\n"; print "The value of \$\$rnd_phash{purple} is $$rnd_phash{purple}\n";
-Jim
|
|---|