/home/wpollock1/public_html/restricted/ShellScripting/url2html

#!/usr/bin/perl
#
# url2html - This script reads URL encoded (CGI) input and prints
# the name, value pairs to stdout, after converting the values
# to HTML.
#
# Some useful test data:  (echo the following and pipe into url2html)
# one=bar&two=two+words&three=foo%26bar%0Aline%20two&four=%3Ctag%3E+you%27re+it!
#
# Written 6/2003 by Wayne Pollock, Tampa Florida USA.

# Read the input into $_ buffer:
# For CGI use, replace the loop with a single read like this:
#     read ( STDIN, $_, $ENV{CONTENT_LENGTH} );

while ( <> )
{
    # Remove trailing newline:
    chomp;

    # Split into an array (@_) of NAME=VALUE pairs:
    split( /&/ );

    # Process each pair by decoding the URL-encoded VALUE,
    # then translating to HTML, and finally storing in a hash:
    foreach ( @_ )
    {
        ($name, $val) = split( /=/ );

        # URL decoding:
        $val =~ tr/+/ /;
        $val =~ s/%([a-fA-f0-9][a-fA-f0-9])/pack("C",hex($1))/eg;

        # HTML conversion:
        $val =~ s/&(?!amp;)/&amp;/g;
        $val =~ s/</&lt;/g;
        $val =~ s/>/&gt;/g;
        $val =~ s/\n/<br>/g;

        print "$name = $val<br>\n";
    }

    print "\n<hr><br>\n\n";
}