David Gilden writes ..
>Here is code fragment that I can't seem to solve.
>All help, suggestions are appreciated.
>Thanks!
>Dave
>
>What I want to do is to check for either if the username or
>password is good:
>
>The $pwfile contains (exactly like it is here):
>username1|password1
>username2|password2
>ect.....
>
>
># stuff $pwd in to @indata
>open(FILE,$pwfile) || die &dead("Can't find $pwfile. $!");
>@indata = <FILE>;
>close(FILE);
all fine
># populate a hash , I am guessing here!
>foreach (@indata){
>($x,$y) = split(/\|/,$_);
>$users{$x} = $y;
>}
oops .. $y still contains the end-of-line character here .. you probably
didn't want that .. so instead you should use
chomp( $users{$x} = $y);
which chomps off that character as the assignment is done
># loop and process each record from $pwd
>foreach $i (@indata) {
so here you get a bit confused .. you've already gone through @indata and
stored the usernames and passwords in the %users hash .. so there's no need
to loop again .. you just want the following lines
>while (($test_username,$test_password) = each %users) {
># print "$test_username,$test_password\n";
># print "$in{'name'} $in{'pwd'} \n";
>#&dead("Bad username , Sorry") if ($in{'name'} ne $test_username);
>#&dead("Password, Sorry") if ($in{'pwd'} ne $test_password);
>}
now the equality test has a chance of succeeding because in the %users hash
you're not storing the line-ending character .. so before you were basically
trying to compare
"username1" with $in{name}
which would have been ok .. but then you also compared
"password1\n" with $in{pwd}
which would almost certainly never match
--
jason king
In Spearfish, South Dakota, if three or more Indians are walking down
the street together, they can be considered a war party and fired
upon. - http://dumblaws.com/