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 ...
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
This topic is archived. New comments cannot be posted and votes cannot be cast.
Responses to this topic
Just wrote a script:
Code:
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
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...
I'm sure you know these things Philipp - I just thought that as a PERL newbie he should be aware of them...
I used a little different method but it still works
Code:
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.
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.