in reply to randomly choosing an alphabetic letter
my @letters = 'E' .. 'Z'; my $drive = $letters[rand scalar @letters];
As you remove letters (say, using splice from @letters), this would continue to work.
Update: Yes, as Limbic~Region points out, the scalar is probably superfluous. I just like being explicit - especially when I'm not looking at the docs to see what the parameters really are. ;-)
Update2: Typo - had slice rather than splice. Thanks to Limbic~Region for pointing it out.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: randomly choosing an alphabetic letter
by Limbic~Region (Chancellor) on Mar 15, 2005 at 23:46 UTC |