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

Re: Array Problem

Thread Previous | Thread Next
From:
Leon
Date:
January 16, 2002 23:04
Subject:
Re: Array Problem
Message ID:
00ab01c19fab$6905db20$b157a9cb@S7575530
----- Original Message -----
From: "maureen" <conlon434@home.com>
To: <beginners@perl.org>

> Currently, the array seems to only be picking up the last name listed in
> the text 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);
> }
<snip off>
> #check for proper password
> if ($username!=~/$in{'username'}/)
> {
> #invalid password--create error message and exit
> print &PrintHeader;

In the foreach loop, after iteration, $username,$password received the last
line of the file. What you really want is to check
$in{'username'} against every line of the file, to do this, you must check
within the foreach loop like this :-

foreach $i (@indata){
             chomp $i;
             ($username,$password) = split(/\|/,$i);
             if ($username !~ /$in{username}/) {
                # I would prefer to use ne instead of !~
                #invalid password--create error message and exit
                print &PrintHeader;
                .......
             };
};







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


Thread Previous | Thread Next


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