Hello all,
I am trying to edit a file using html and perl. I got it working but I
wanted to know if this i the best way to do the job. I have a problem with
the first line being blank. Everytime I submit I get a new blank line at
the top of my file:
(some HTML removed....)
#!/usr/bin/perl
$|=1; # no buffering, ??
$allow_html_code = 1;
$ExceptionSiteList = '/etc/dansguardian/famlists/exceptionsitelist';
# URL to this CGI
$myurl = "/access/banned.pl" ;
&ReadEnvs;
my $urllist = $in{'input3'};
if ($urllist ne "") {
open (EFILE, ">$ExceptionSiteList") or die "Can't open $file: $!\n";
print EFILE "$urllist";
close EFILE;
}
print <<EOE ;
.
.
.
<FORM ACTION="$myurl" METHOD="POST"><textarea rows="40" name="input3"
cols="50">
EOE
open (FILE, "<$ExceptionSiteList") or die "Can't open $file: $!\n";
while (<FILE>) {
chomp;
print "$_";
}
close FILE;
print qq(</textarea><input type="submit" value="Submit"
name="B5"> <input
type="reset" value="Undo" name="B6"></form></td></tr>);
print "</table></body></html>";
sub ReadEnvs {
local($cl, @clp, $pair, $name, $value);
if ( $ENV{'REQUEST_METHOD'} eq 'POST' ) {
read(STDIN, $cl, $ENV{'CONTENT_LENGTH'} );
}
else {
$cl = $ENV{'QUERY_STRING'};
}
@clp = split(/&/, $cl);
foreach $pair (@clp) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($allow_html_code != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$in{$name} = $value;
}
}
Ryan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/