On Jun 4, Sven Bentlage said:
>using the code below I only get the last line from the file.
Let's look at your loops:
while (<USER>) {
@user = split /;/;
}
That loops over each line of the file, splits the line on semicolons, and
sets the @user array to that list returned. You are OVERWRITING the @user
array each time.
foreach ($_) {
unless ($f_name eq $user[0] and $f_pw eq $user[1]) {
print_data($user[0]);
exit;
}
else {
get_name();
exit;
}
}
First, your foreach loop is looping over $_, which at this point holds no
useful value. Your loop will run ONCE. Also, you're calling exit() in
your loop! exit() exits the PROGRAM -- so even if the rest of the program
was right, this would STILL exit the program after the FIRST iteration.
I have a feeling you want to write the code like so:
while (<USER>) {
chomp; # remove the newline
my @user = split /;/;
if ($f_name eq $user[0] and $f_pw eq $user[1]) {
print_data($user[0]);
}
else {
get_name();
}
}
I'm not sure where you'd want exit() in that code.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]