CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
need some quick help

 



Mel
Deleted

May 22, 2000, 4:02 PM

Post #1 of 4 (469 views)
need some quick help Can't Post

can anyone tell me what's wrong with the following code?

$username = $FORM{'username'};
$password = $FORM{'password'};

open(DATA, "$mainpwd");

@data = <DATA>;
while (($username ne "$usrname") and ($password ne "$pwd")) {
$theline = "$_";
chomp($theline);
($usrname, $pwd, $location) =
split(/::/, $theline);
}
print "Location: $location\n\n";


japhy
Enthusiast

May 26, 2000, 10:25 PM

Post #2 of 4 (469 views)
Re: need some quick help [In reply to] Can't Post

The problem with your code was that you never put anything in $_. You probably meant to do something like:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open FILE, $mainpwd or die "can't open $mainpwd: $!";
while (<FILE> ) {
($uname,$pwd) = split /::/;
chomp($theline = $_), last if $uname eq $username and $pwd eq $password;
}
close FILE;
</pre><HR></BLOCKQUOTE>


kencl
User

May 27, 2000, 1:29 AM

Post #3 of 4 (469 views)
Re: need some quick help [In reply to] Can't Post

The syntax of the conditional expression should not contain quotes, and you need to use "&&" instead of "and". This is how it should look:

(($username ne $usrname) && ($password ne $pwd));

Note that $usrname and $pwd are undefined initially, and I'm not sure if this will cause a problem. I would guess that (UNDEFINED ne ANYDEFINEDANYTHING) would return true, but I'd test that assertion before relying on it.

I'd do it like this:

$key = $username.":".":".$password;
@Valid = grep(/^$key/, @data);
($usrname, $pwd, $location) = split(/::/, $Valid[0]);
chomp($location);
print "Location: $location\n\n";

Alternatively:

foreach $line (@data) {
chomp($line);
($usrname, $pwd, $location) = split(/::/, $line);
last if (($username eq $usrname) && ($password eq $pwd));
}
print "Location: $location\n\n";

The second way is probably better since it stops looking as soon as it finds a match. The grep function above works through every line in @data.

Good luck!


TheGame+
Deleted

May 27, 2000, 2:48 PM

Post #4 of 4 (469 views)
Re: need some quick help [In reply to] Can't Post

See the same thread on the Intermediate board...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives