in reply to Why do I get uninitialized value in substitution (s///) in my array?

Is it possible that when you try to substitute the passwords your ldif file has more than 53 lines? You are shifting one password off @genpass for each line in your ldif file. This is one password for each user only if your ldif file has one line for each user.

  • Comment on Re: Why do I get uninitialized value in substitution (s///) in my array?

Replies are listed 'Best First'.
Re^2: Why do I get uninitialized value in substitution (s///) in my array?
by xjlittle (Beadle) on Aug 13, 2009 at 17:09 UTC
    ig,
    That worked the 2nd time that I tried it. I'm not sure why it didn't work the first time.
    Thanks!

      I would probably write your script something like the following, avoiding the problem of how many passwords to generate.

      use strict; use warnings; my $users = "new.users"; open(my $in, '<', $users) or die "Cannot open $users: $!"; my $tmp = $users . '.tmp'; open(my $out, '>', $tmp) or die "Cannot open $tmp: $!"; foreach (<$in>) { if(/^userPassword: xyz456$/) { my $pw = generatePassword(10); s/^userPassword: xyz456/userPassword: $pw/; } print $out "$_"; } close($out); close($in); unlink($users) or die "unlink($users): $!"; rename($tmp, $users) or die "rename($tmp, $users): $!"; exit(0); sub generatePassword { my $length = shift; my $password = ""; my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRST +UVWXYZ'; while (length($password) < $length) { $password .= substr($possible, (int(rand(length($possible)))), 1); } return $password }