Nice solution.
Downsides:
- This recreates the 62 element list repeatedly in memory, since there's
no place to store it.
- The number "62" is hardcoded, and must match the list exactly. That's
a maintenance headache: suppose a requirement came along to ensure that
underscore were included, or that digits were not.
- The int is redundant.
Implementing these three changes, I'd go with something like:
BEGIN {
my @source = ('A'..'Z', 'a'..'z', '0'..'9');
sub generate_random_password {
my $id = "";
for (1..18) {
$id .= $source[rand @source];
}
$id;
}
}
For so-called "pronounceable" passwords, try
Crypt::RandPasswd. Looks nice, and based on a government standard.
-- Randal L. Schwartz, Perl hacker