LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-24-2004, 01:01 PM   #1
morbid_ru
LQ Newbie
 
Registered: Dec 2003
Posts: 6

Rep: Reputation: 0
Need help with perl loop!


Hello.

I have name/pass .txt file like this:

name1|ftftft
name2|sesese

I would like this file to be compared to the $FORM{'name'} and $FORM{'password'} values and upon the match, deciee what to do. However things are not working.
Here is my code:

####
sub pass {
$cryptpass = crypt($FORM{'password'}, "ts");
open(FILE,"$pass_file");
@lines = <FILE>;
close(FILE);
for ($lines_no = 0; $lines_no <= $#lines; $lines_no++) {
chomp($lines[$lines_no]);
($name, $password) = split(/\|/, $lines[$lines_no]);
if ($FORM{'name'} =~ $name) || (crypt($FORM{'password'}, "ts") =~ $password)
{
&intro;
}
else {
&badlogin;
}
}
exit;
}
########
 
Old 02-24-2004, 01:14 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You will probably be easier using foreach and chop:
Code:
sub pass {
 $cryptpass = crypt($FORM{'password'}, "ts");
 open(FILE,"$pass_file");
 @lines = <FILE>;
 close(FILE);
 foreach $line (@lines){
  chomp($line);
  ($name, $password) = split(/\|/, $line);
  if ($FORM{'name'} eq $name && $cryptpass eq $password){
   &intro;
  }
  else {
   &badlogin;
  }
 }
 exit;
}

Last edited by david_ross; 02-24-2004 at 01:15 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to break if loop in Perl? Barca Programming 9 08-03-2011 01:15 PM
Perl: Where am I in a foreach loop? jrtayloriv Programming 3 01-30-2005 10:43 PM
loop through string with perl lfur Programming 2 07-03-2004 08:05 AM
Need help with perl loop! morbid_ru Programming 2 02-17-2004 05:15 AM
Loop in this perl script is not working meluser Programming 2 04-01-2003 08:59 PM


All times are GMT -5. The time now is 10:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration