#!/usr/bin/perl # &parse_form; foreach $name (keys %lookup) { $file = $name; } if ( $file != "(\w+)\.html" ) { &suicide("I'm sorry the URL $file is invalid."); } open (INPUT, "$file") || &suicide ("Sorry."); while () { $input .= $_; } close(INPUT); $input =~ s|| http://www.hrw.org/wr2k2/$file

|g; $input =~ s|||g; $input =~ s|| Human Rights Watch World Report 2002|; $input =~ s| MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0"||; $input =~ s|([\n\r ]*)||g; $input =~ s|([\n\r ]+)([\n\r ]+)
||; $input =~ s|\t  ((.*)[\n\r ]+)+||; open(output, '>-'); print(output "Content-type: text/html\n\n"); print(output $input); close(output); exit; sub suicide { local($error_text) = @_; print "Content-type: text/html\n\n"; print" Error
$error_text "; exit; } # End of suicide, end of program sub parse_form { local (*lookup) = @_; local ( $request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &suicide ("Server Error uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($lookup{$key})) { $lookup{$key} = join ("\0", $lookup{$key}, $value); } else { $lookup{$key} = $value; } # end if } # end foreach @list = %lookup; } # end sub parse_form sub showme { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "Elements in the associative array\n"; print "\n"; print "\n"; print "form got:
\n\n$input

"; foreach $name (keys %lookup) { print "$name = $lookup{$name}

\n\n"; } print "\n"; print "\n"; exit; }