http://qs321.pair.com?node_id=7379


in reply to Random letters

foreach $x ('a' .. 'z') {$alph->{$y} = $x; $y++;} foreach (0 .. 25) {$b = rand 25; $alph->{int $b}, "\n";} This will print out 25 random letters from the hash...you can change that to print out however many you want. Maurice

Replies are listed 'Best First'.
RE: RE: Random letters
by chromatic (Archbishop) on Apr 12, 2000 at 18:44 UTC
    Hmm, you've just reinvented the array. :)

    Seriously, there's no advantage in using a hash with ascending numeric keys corresponding to the letters of the alphabet (especially as you use zero as a base) over a simple array.

    The array is faster and slightly easier to read, too, not to mention much easier to initialize: my @letters = (a .. z);

      Duh...I should have realized that. It seemed fine when I ran it, but looking at the other versions, I see now my mistake! :) Still not bad for a Perl newbie. I did not partake of one of the three virtues: laziness. doh! thanks for the insight. -Maurice