in reply to Re: While loops with if
in thread While loops with if

The program is doing what you told it to do. It is looping forever, because you didn't include any way for the loop to end. And it's printing a null password because you never generate a password. The point of the loop is to generate passwords, and keep generating them, UNTIL one is found which has not been generated before.

Please read this and try to understand.
# define these outside the loop, please. my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & *) ); # load the previously generated passwords from the file: my $usedpw = "logfile.txt" ; open USEDPW, "< $usedpw" or die "Error opening $usedpw for reading: +$!\n"; flock USEDPW, 1; # shared lock my @used_pw = <USEDPW>; close USEDPW; chomp @used_pw; # and put them in a set (implemented as a hash): my %used_pw; for ( @used_pw ) { $used_pw{$_}++ } my $pw; do { # create a password: $pw = join '', @chars[map{rand @chars} (1..17)]; } while exists $used_pw{$pw}; # we now have a password which has not been used before, so report i +t print "Your unique password is: $pw\n"; # and store it in the file. open USEDPW, "> $usedpw" or die "Error opening $usedpw for writing: +$!\n"; flock USEDPW, 2; # exclusive lock print USEDPW "$pw\n"; close USEDPW;

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.