Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Checking username and password but cant break whileloop!

by tobyink (Abbot)
on Nov 09, 2012 at 16:06 UTC ( #1003175=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED] Checking username and password but cant break whileloop!

I think you want the last function.

my $match = 0; # We haven't got a match yet. while ($lines = <PSWD>){ ($user,$pswd,$userID,$groupID,$info,$home,$shell) = split ':', $lin +es; if ($username eq $user) { print "Checking username... MATCH\n"; if ($passwd eq $pswd){ print "Checking password... MATCH\n"; } else { print "Password does not match!\n"; } $match = 1; # We have found a match last; # So stop looping already! } } unless ($match) { print "\"$username\" does not match any users in our database!\n"; }

Update: I have also moved that else outside of the loop as an unless block.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Checking username and password but cant break whileloop!
Select or Download Code
Re^2: Checking username and password but cant break whileloop!
by jaffinito34 (Acolyte) on Nov 09, 2012 at 16:10 UTC

    Same thing happened, it printed "...does not match..." for each user in the file rather than just once. Where you have it is for when the username is correct, which I don't have any issues with. It's when the username entered is incorrect that is giving me problems.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-12-22 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls