xjlittle has asked for the wisdom of the Perl Monks concerning the following question:
Grandfather, here is the data file. This is repeated 52 times with a blank line between each user's info. This line is constant with all entries and in the same place each time: userPassword: xyz456#!/usr/bin/perl -w use strict; my $p = 1; my @genpass; my $genpass; my $pass = "/home/v0x9849/scripts/new.pass"; open (PASS, ">", $pass) or die "Cannot open $pass: $!"; while ( $p < 53 ){ @genpass = generatePassword(10); print PASS "@genpass \n"; $p++; } close PASS; open (PASS, $pass) or die "Cannot open $pass: $!"; @genpass = (<PASS>); my $a; my $users = "/home/v0x9849/scripts/new.users"; open (USERS, $users) or die "Cannot open $users: $!"; my @nup = (<USERS>); close USERS; open (USERS, ">", $users) or die "Cannot open $users: $!"; foreach (@nup){ # print "$genpass[0]\n"; <==this works s/xyz456/$genpass[0]/; <==this gets uninitialized #print USERS; $a = shift(@genpass); } close USERS; #print generatePassword(10) . "\n"; #exit; sub generatePassword { my $length = shift; my $password = ""; my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWX +YZ'; while (length($password) < $length) {$password .= substr($possible, (i +nt(rand(length($possible)))), 1);}return $password}
@ig, @graff There are 728 lines total including blanks between each user's data entry. When I set the iterations to 728 it made the file 0 bytes. However this does seem reasonable as it would have to go through each line. Any ideas on how to prevent it from going to 0 bytes? @desemondo The only thing copied is the password generation script which is not the issue. When I tried your suggestion with 53 iteration I got the same error. When I tried it with 728 it also made the file 0 bytes. @jwkrahn That may work but we are not allowed to add modules to our workstations.__DATA__ dn: uid=1234567,ou=people,dc=abc,o=oursite.com objectClass: posixAccount objectClass: shadowAccount objectClass: account objectClass: top uid: 1234567 cn: 1234567 uidNumber: 31472 gidNumber: 7546 gecos: First Last,ABCDEFG297,####### homeDirectory: /home/1234567 loginShell: /bin/csh userPassword: xyz456 <==constant line
|
|---|