develooper Front page | perl.beginners | Postings from January 2002

Re: Array Problem

Thread Previous
From:
Leon
Date:
January 21, 2002 16:30
Subject:
Re: Array Problem
Message ID:
009101c1a362$398933a0$3848a9cb@S7575530
----- Original Message -----
From: "maureen" <conlon434@home.com>
To: "Leon" <eventualdeath@yahoo.com>
Cc: <beginners@perl.org>
Sent: Monday, January 21, 2002 8:39 AM
Subject: Re: Array Problem

> if ($username ne /$in{username}/)
> {

Anything in between the forward slash are usually used as a regular
expression such as ~s/$..../ or m/.../ whereas things like ne, eq, lt are
straight forward matching operators that dont require forward slash.

Try changing the above to the following and see if it works :-
if ($username ne $in{username}) {.........};

#### end of my msg #######

> Thanks so much for your help on this. I tried this suggestion, but
> unfortunately, the array @indata does not seem to contain the usernames
> from the file pwdata.txt.
>
> I've been looking at this for hours. I hope someone can help me figure
> out what I am missing here. The objectives for this code and the revised
> code follow:
>
> Code Objectives:
> 1)Accept username and password from an HTML page
> 2)Open a text file and store the username and passwords listed there in
> an array
> 3)Compare the username and password in the array to the username and
> password entered on the HTML page.
> 4)If username and password match, direct the user to another web page.
> 5) If username and password do not match or fields are left blank on the
> HTML form, direct user to an error page.
>
> Revised code:
> #!/usr/local/bin/perl
> require "cgi-lib.pl";
> #process incoming form data
> &ReadParse;
> #open the database in read-only mode
> open(FILE,"pwdata.txt") || die "Can't find database\n";
> #store database contents in an array and close file
> @indata = <FILE>;
> close(FILE);
> foreach $i (@indata)
> {
> #remove hard return character from each record
> chomp($i);
> #split fields on pipe character
> #assign a variable name to each of the fields
> ($username,$password) = split(/\|/,$i);
> if ($username ne /$in{username}/)
> {
> #invalid password--create error message and exit
> print &PrintHeader;
> print <<"PrintTag";
> <HTML>
> <HEAD>
> <TITLE>Error!</TITLE>
> </HEAD>
> <BODY BGCOLOR="white" TEXT="black">
> <H1>Authorization Required</H1>
> <BLOCKQUOTE>
> You do not have authorization to enter this website. Please click <a
> href="http://www.worldwidewebstrategies.com">here</a>
> to return to the WWWS web site.
> </BLOCKQUOTE>
> <BLOCKQUOTE>
> If you feel you have received this message in error, please return to
> the
> login screen and try to enter your username and password again.
>  </BLOCKQUOTE>
> </BODY>
> </HTML>
> PrintTag
> exit(0);
> }
> #check for blank form fields
> if ($in{'username'}eq"" || $in{'password'}eq"")
> { #invalid password--create error message and exit
> print &PrintHeader;
> print <<"PrintTag";
> <HTML>
> <HEAD>
> <TITLE>Error!</TITLE>
> </HEAD>
> <BODY BGCOLOR="white" TEXT="black">
> <H1>Authorization Required</H1>
> <BLOCKQUOTE>
> You do not have authorization to enter this website. Please click <a
> href="http://www.worldwidewebstrategies.com">here</a>
> to return to the WWWS web site.
> </BLOCKQUOTE>
> <BLOCKQUOTE>
> If you feel you have received this message in error, please return to
> the
> login screen and try to enter your username and password again.
>  </BLOCKQUOTE>
> </BODY>
> </HTML>
> PrintTag
> exit(0);
> };
> #check for existence of lock file
> if (-e "lock.fil")
> {
> #lock file exists! print message & shut down
> print &PrintHeader;
> print <<"PrintTag";
> <HTML>
> <HEAD>
> <TITLE>File in use</TITLE>
> </HEAD>
> <BODY BGCOLOR="white" TEXT="black">
> <H1>Try again!</H1>
> <BLOCKQUOTE>
> The database is in use. Please try again later.
> </BLOCKQUOTE>
> </BODY>
> </HTML>
> PrintTag
> exit(0);
> }
> #everything is okay. Create lock file.
> open(LOCK_FILE, ">lock.fil");
> #open, append record, and close database
> open(FILE,">>data.txt") || die "Can't find database\n";
> print FILE
> "$in{'username'}|$in{'password'}\n";
> close(FILE);
> #close lock file
> close(LOCK_FILE);
> #delete lock file
> unlink("lock.fil");
> #print database contents
> print "Location:http://www.worldwidewebstrategies.com\n\n";
> };
>



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About