Current location: Hot Scripts Forums » Programming Languages » Perl » Reading Txt files


Reading Txt files

Reply
  #1 (permalink)  
Old 01-17-05, 07:23 PM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Reading Txt files

Ok i have a text file with info in the following format
Code:
username:password:rank:str:level:agi
lol that rough from the top of my head i use to use a code(now long forgotten) to sperate the usernamme,password etc into variables. so i can make like a login using a .txt file making sure that if username = theusername in the .txt file and the password = the password in the .txt can anyone help?
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
  #2 (permalink)  
Old 01-19-05, 10:51 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Are you looking for help with the split command?

Code:
open DATA, ...
while (<DATA>) {
  my %user;
  @user(qw(username password rank str level agi)) = split /:/;
  # Code to auth below
  if ($user{'username'} == $username && $user{'password'} == $pass) { ... }
}
...or are you looking for working code?

~Charlie
Reply With Quote
  #3 (permalink)  
Old 01-20-05, 05:44 AM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
that should work wonderfully thanks
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
  #4 (permalink)  
Old 01-20-05, 06:43 AM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
lol nope that didn't work it gave errors got anything simpler? lol
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
  #5 (permalink)  
Old 01-20-05, 09:50 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Well, that is just pseudocode. You need to fill in the blanks to make it work. You really didn't provide enough info nor do I have the time to write the code for you[1]. If you make an attempt at doing it yourself and you get stuck than I am more than willing to help. Give it a go and post back your code if you run into problems.

[1] If you want me to write the code for you send me the specs via PM and I'd be happy to provide you with a quote and turn around time. I'm pretty booked up with custom work at the moment though.

~Charlie
Reply With Quote
  #6 (permalink)  
Old 01-20-05, 10:20 AM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
i filled in the blanks but i got the error
syntax error at index.cgi line 12, near "$pass



print"
Global symbol "@user" requires explicit package name at index.cgi line 21.
syntax error at index.cgi line 21, near "@user("
Global symbol "$username" requires explicit package name at index.cgi line 23.
Execution of index.cgi aborted due to compilation errors.
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
  #7 (permalink)  
Old 01-20-05, 11:36 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Post your code for me. It looks like I might have goofed the hash splice.

~Charlie
Reply With Quote
  #8 (permalink)  
Old 01-20-05, 12:06 PM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
#!/usr/bin/perl -wT
use strict;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
print "content-type: text/html\n\n";

my $user = param('user');
my $pass



print <<"NO HTML";
<html>
<head>
<title>Tempest's Aim Sub Profile</title>
</head>
NO HTML
open (DATA, "users.db");
while (<DATA>) {
my %user;
@user(qw(username password hits)) = split /:/;
# Code to auth below
if ($user{'username'} == $username && $user{'password'} == $pass) {
print <<"NO HTML";
<h3>
Hello </h3>
NO HTML

}
}
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
  #9 (permalink)  
Old 01-20-05, 01:35 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
I used ('s in the hash slice instead of {'s...

Code:
#!/usr/bin/perl -wT
use strict;
use CGI; # ':standard';
use CGI::Carp qw(fatalsToBrowser);

my $in = CGI->new;

#my $username = $in->param('user');
#my $password = $in->param('pass');
my $username = "Charlie";
my $password = "pass";

print $in->header;
print "<html>\n<head>\n  <title>Tempest's Aim Sub Profile</title>\n</head>\n";
print "<body>\n";

my %user;
#open (DATA, "users.db") or die "Failed to read-open DB: $!";
while (<DATA>) {
  %user = ();
  @user{qw(username password hits)} = split /:/;
  if ($user{'username'} eq $username && $user{'password'} eq $password) {
    print "<h3>Hello $user{'username'}</h3>\n";
  }
  # Or if you just want to grab the user data for later use
  #last if ($user{'username'} eq $username && $user{'password'} eq $password)
}
print "</body>\n";

__DATA__
username:password:rank:str:level:agi
Charlie:pass:general:100:100:100
~Charlie
Reply With Quote
  #10 (permalink)  
Old 01-20-05, 01:52 PM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
ok that don't give me any errors but what would the link look like? www.scriptlink.com/index.cgi?WHAT HERE?
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading / Writing files andreasberglind ASP.NET 1 12-27-04 06:41 AM
reading files backwards kosa PHP 3 11-09-04 11:50 PM
calling txt files waji ASP 7 11-01-04 12:48 PM
Reading .lnk file(shortcut files in windows) anupamsr PHP 5 04-22-04 02:42 PM
How to do fopen all files at a time and show one line from all files. Mouse PHP 0 03-01-04 08:33 PM


All times are GMT -5. The time now is 04:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.