Update - I'm crazy. while does set $_, but I customarily chomp in the fashion above and I guess I forgot why. :-(while (chomp($_ = <FILE>)) { do stuff; }
The above code shouldn't compile. The foreach after it is also completely unnecessary (no sense looping over 1 value). Maybe it ought to look something like:
Adjust the return values to suit the logic of your program. I assume that at a minimum you might like to know if the user exists in the user list and whether or not their password is correct.my $user = $q->param('username'); my $pass = $q->param('password'); verify($user, $pass) or die "No user or password incorrect"; sub verify { my ($ck_user, $ck_pass) = @_; open FH, $user_file" or die "Can't open file, $!"; while (chomp($_=<FH>)) { my ($user, $pass) = split '\|'; if ($user eq $ck_user) { if ($pass ne crypt(ck_pass)) { return 0; } else { return 1; } } } return 0; }
In reply to Re: Reading from multi line file -> CGI.pm
by virtualsue
in thread Reading from multi line file -> CGI.pm
by FireBird34
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |