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

Re: Array Problem

Thread Previous | Thread Next
January 16, 2002 23:04
Re: Array Problem
Message ID:
----- Original Message -----
From: "maureen" <>
To: <>

> 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 address at

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About