Busby 0 Posted July 3, 2001 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. Share this post Link to post
Philipp 6 Posted July 3, 2001 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 Share this post Link to post
CUViper 0 Posted July 4, 2001 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... Share this post Link to post
Busby 0 Posted July 5, 2001 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. Share this post Link to post