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.
Page 1 of 1
More PERL help
#2
Posted 03 July 2001 - 10:32 PM
Just wrote a script:
I hope that help you
Code:
$NAME = "Username"; # Example Variable open(FILE, "member.dat"); # File while(<FILE>) { $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 list print FILE "$NAME\n"; close(FILE); print "$NAME added to the list"; exit;
I hope that help you
#3
Posted 04 July 2001 - 04:22 AM
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...;)
#4
Posted 05 July 2001 - 05:04 PM
I used a little different method but it still works
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.
Share this topic:
Page 1 of 1

Help










