Array Problem

2002-01-15 Thread maureen

Hello! I hope someone can help me.  

I am working on the following code, written to accomplish these tasks:

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.

Currently, the array seems to only be picking up the last name listed in
the text file.  

Would you please take a look at my code to help me see what I have done
wrong?

Thanks, Maureen

#!/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);
} 
#check for blank form fields  
if ($in{'username'}eq || $in{'password'}eq)  
{ 
#set content type 
} 

#check for proper password  
if ($username!=~/$in{'username'}/) 
{ 
#invalid password--create error message and exit  
print PrintHeader; 
print PrintTag;  
HTML  
HEAD  
TITLEError!/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Authorization 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  
TITLEFile in use/TITLE  
/HEAD  
BODY BGCOLOR=white TEXT=black  
H1Try 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;;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Array Problem.

2001-12-10 Thread Andre` Niel Cameron

Hi,

I have a prob:)  I need to search threw an array and remove an item based on
its name.  I was thinking about maybie a for each loop but I am not sure how
to go about it.  Heres what I need to do:

say $object= sword;
I have an array @AllObjects('beer', 'nuts', 'sword', 'and more stuff')
Now sword may or may not ever be in the same location of the array so a
simple shift will not work here.  I need to find a way to pull sword out of
that array.  Any help is as always greatly appreciated:)


Regards,
Andre` C.
Technical Support
ԿԬ

-
Visit our support manual at http://supportmanual.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Array Problem.

2001-12-10 Thread Curtis Poe

--- Andre` Niel Cameron [EMAIL PROTECTED] wrote:
 Hi,
 
 I have a prob:)  I need to search threw an array and remove an item based on
 its name.  I was thinking about maybie a for each loop but I am not sure how
 to go about it.  Heres what I need to do:
 
 say $object= sword;
 I have an array @AllObjects('beer', 'nuts', 'sword', 'and more stuff')
 Now sword may or may not ever be in the same location of the array so a
 simple shift will not work here.  I need to find a way to pull sword out of
 that array.  Any help is as always greatly appreciated:)
 
 
 Regards,
 Andre` C.
 Technical Support
 ԿԬ

@AllObjects = grep { $_ ne 'sword' } @AllObjects;

Or, if you're not sure about the case:

@AllObjects = grep { $_ !~ /^sword$/i } @AllObjects;

See 'perldoc -f grep'

Cheers,
Curtis Ovid Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
Ovid on http://www.perlmonks.org/

__
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]