Derek B. Smith wrote:
--- "Mumia W." <[EMAIL PROTECTED]>
wrote:

What is the purpose of this program?

To generate a random 6 character string.
If the first character starts with a # then I just
ignore the new string and tell it to goto LABLE, b/c
for 0-32 on the ASCII table cannot be used as a 1st
character in a user password.

## generate random 8 char password.
PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $password = join '', map { $a[int rand @a] } 0 ..
5;

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack ("A1" x length($password),
$password);
if ($chars[0] =~ /^\D/) {
  print "Your new password is:\t",@chars,"\n";
}
else {
  #print "string starts with number:\t",@chars,
"\trestarting\n";
  #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e);
## execute with regexp substitute ?/? goto PASSWD;
}

This will do what you want. It shuffles all of the possible characters and joins
them into a string, and then finds the first substring of six characters that
starts with a non-numeric character. The only proviso is that a password can
never have the same character twice, which isn't true of the general solution.

  use List::Util qw/shuffle/;

  my $chars = join '', shuffle (0..9, 'a'..'z', 'A'..'Z');
  my ($password) = $a =~ /(\D.....)/;

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to