Jaxonn has asked for the wisdom of the Perl Monks concerning the following question:
#!c:/perl/bin/perl -w print "Content-type: text/html\n\n"; use CGI; ####################################################### ## © Copyright 2002 All Rights Reserved ## ## Mr. Andrew Jackson ## ####################################################### ##Start the parsing of the form @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; if (defined($Config{$name})) { $Config{$name} = $value; } else { if ($Form{$name} && $value) { $Form{$name} = "$Form{$name}, $value"; } elsif ($value) { push(@Field_Order,$name); $Form{$name} = $value; } } } ##End Parsing ##This next line sets up the view of the webpage print "<html><head><title>|ReD| - $Form{'han'} - Kick Vote</title><sty +le type='text/css'><!--body {background-color: black; color: white; f +ont-family: Tahoma; font-size: 13}A:link, A.:active, A:visited {color +: white; text-decoration: none}A:hover {color: red}--></style></head> +<body><center><a href='progress.cgi' border='0'><img src='http://jksn +.net/img/indexpic.jpg' border='0' width='60%' height='150'></a><br><O +BJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase=' +http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#v +ersion=5,0,0,0' WIDTH=600 HEIGHT=80> <PARAM NAME=movie VALUE='http:// +jksn.net/title.swf'> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgco +lor VALUE=#000000> <EMBED src='http://jksn.net/title.swf' quality=hig +h bgcolor=#000000 WIDTH=600 HEIGHT=80 TYPE='application/x-shockwave- +flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/inde +x.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT><p><table widt +h='100%' border='0'><td rowspan='*' width='20%'><!-- URL's used in th +e movie--><A HREF=news.html></A> <A HREF=members.html></A> <A HREF=jo +in.html></A> <A HREF=about.html></A> <A HREF=screenshots.html></A> <A + HREF=links.html></A> <A HREF=http://forum.jksn.net></A> <!-- text us +ed in the movie--><!--News Members Join About Screenshots Links Forum + --><OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' code +base='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash +.cab#version=5,0,0,0' WIDTH=150 HEIGHT=400> <PARAM NAME=movie VALUE=' +http://jksn.net/nav2.swf'> <PARAM NAME=quality VALUE=high> <PARAM NAM +E=bgcolor VALUE=#000000> <EMBED src='http://jksn.net/nav2.swf' qualit +y=high bgcolor=#000000 WIDTH=150 HEIGHT=400 TYPE='application/x-shoc +kwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/downloa +d/index.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT></td><td + valign='top'>"; #This next if statement checks to make sure the user inputted a valid +code from a form if (($Form{'code'} eq "XXXXXXXXXXXXXX") || ($Form{'code'} eq "XXXXXXXX +X") || ($Form{'code'} eq "XXXXXXX")){ open(kick, "$Form{'han'}.txt"); #This opens a file with the membe +rs handle @kick = <kick>; #this reads it close(kick); #closes it foreach (@kick){ chomp; #chomps it } $kick = @kick[0]; #This checks to see if the file is blank specificaly doesn't have + a first line if($kick eq ""){ $kick = 1; #makes the kickvote total 1 print "The new kick vote total is $kick","/","3"; #prints to +tal @kick = ($kick, $Form{'code'}, "-", "-"); #stores the kickvo +te total, code used to vote, and the two place holder for the other r +equired codes to kick a member } else { $codeok = 1; #place holder #this checks to see if the inputed code has been used before foreach $line (@kick){ if ($line eq "$Form{'code'}"){ $codeok = 0; #if the code has been used, this is s +et to 0 print "That code has already been used"; } } #runs this if code has not been used if ($codeok == 1){ $kick++; #adds 1 to the total @kick[0] = "$kick"; #stores $kick to the aray $kicks = join('#', @kick); $joins all the keys in @kick + together for editing $kicks =~ s/-/$Form{'code'}/; #replacing the first enco +untered "-" with the code inputted @kick = split(/#/, $kicks); #splits it back up print "The new kick vote total is $kick","/","3"; } } #this checks to see if all the codes have voted to kick the membe +r if ($kick == 3){ open(memb, "membs.txt"); #opens membs.txt for reading @membs = <memb>; #reads .txt file close(memb); #closes foreach (@membs){ chomp; #chomps the \n off } @search = grep(!/&$Form{'han'}&/, @membs); #searches for eve +ry user in the @membs (contents of <membs>) and puts into @search. So + it virtualy takes the user out of the text file open(memb, ">membs.txt"); #opens it for writing foreach $line (@search){ print memb "$line\n"; #prints the contents off the last + membs, but without the kicked member } close(memb); open(THING, "$Form{'han'}.txt"); close(THING); $ext = ".txt"; #stores the extension $filename = "$Form{'han'}$ext"; #defines file to be deleted unlink "$Form{'han'}.txt" or die "Couldn't delete $filename: + $!"; #should delete the file that stored the kickvote total and used + codes print "<br>Member Kicked Out of Clan"; } #this next bit just stores the kick info into the file open(kick, ">$Form{'han'}.txt"); foreach $line (@kick){ print kick "$line\n"; } close(kick); print "<Meta http-equiv='refresh' content='4;url=viewmemb.cgi'>"; } else { print "That is not a valid code."; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help with unlink cont.
by tachyon (Chancellor) on May 06, 2002 at 00:32 UTC | |
|
Re: help with unlink cont.
by Jaxonn (Initiate) on May 05, 2002 at 23:53 UTC | |
|
Re: help with unlink cont.
by Jaxonn (Initiate) on May 07, 2002 at 00:52 UTC |