More PERL help

I need some more help w/ PERL. This time I don't know exactly what to do (I'm a newbie in PERL). What I want to do is search through a file and if the content of a variable is present then redirect to a page saying yuo've already registered, and then if it doesn't exist it writes info to the file and redirects to a ...

Slack Space 1613 This topic was started by ,


data/avatar/default/avatar15.webp

143 Posts
Location -
Joined 2000-04-18
I need some more help w/ PERL. This time I don't know exactly what to do (I'm a newbie in PERL). What I want to do is search through a file and if the content of a variable is present then redirect to a page saying yuo've already registered, and then if it doesn't exist it writes info to the file and redirects to a different page.

Participate on our website and join the conversation

You have already an account on our website? Use the link below to login.
Login
Create a new user account. Registration is free and takes only a few seconds.
Register
This topic is archived. New comments cannot be posted and votes cannot be cast.

Responses to this topic


Administrator

data/avatar/0/0b385d2cbb4fcc3a67cc1faf071a808432c41071.jpg

1795 Posts
Location -
Joined 1999-07-15
Just wrote a script:

Code:
$NAME = "Username"; # Example Variableopen(FILE, "member.dat"); # Filewhile() {$THIS_LINE=$_;chomp($THIS_LINE);if ($THIS_LINE eq $NAME) { print "You are already registered"; exit;}}close(FILE);open(FILE, ">>member.dat"); # Write file if user is not on the listprint FILE "$NAME\n";close(FILE);print "$NAME added to the list";exit; 
I hope that help you

data/avatar/default/avatar27.webp

1117 Posts
Location -
Joined 2000-01-23
Philipp's script looks good to me, but I see two small things to fix if you use this. For one, that exit; in the middle of the script leaves the file open - you should insert a close(FILE); right before it. Also, whenever opening files, it is good practice to verify that the file was opened properly. To do this, just add a die statement, i.e. open(FILE, "member.dat") or die "Error - Couldn't open member.dat: $!";
 
I'm sure you know these things Philipp - I just thought that as a PERL newbie he should be aware of them...

data/avatar/default/avatar15.webp

143 Posts
Location -
Joined 2000-04-18
OP
I used a little different method but it still works
 

Code:
open(FILE,"../www/roster_info/roster.txt");$exists++ if grep(/$name/i,(<FILE>));close(FILE);if ($exists) {print "Content-type: text/html\n\n"; print <<"EOF";<meta http-equiv="refresh" content="0;url=http://www.reservoirdogs.net/roster_info/already.shtml">EOF} else {
 
After the else I have the original contents of the script so it checks first, then it decides whether or not to actually register you (this is for a LAN party registration).
 
*EDIT*
Got the other part I needed done.