#!/usr/bin/perl
#
# define the functions
# mikes_fix_html()
# html_to_dhtml()
# in the file
# perl_use_code.pm
#
# note 1: you include the name WITHOUT the .pm
# note 2: the module must return a value ie: 1 in this case
#
# this web page has a good reference on writting this stuff
#
#http://perl.apache.org/docs/general/perl_reference/perl_reference.html#use____require____do_____INC_and__INC_Explained
#
use perl_use_code;
#
# this URL has some nice info on the PERL LWP functions
#
# http://www.perl.com/pub/a/2002/08/20/perlandlwp.html
#
require CGI;
use CGI;
$cgi = new CGI;
#
# so i can include modules in the current path
#
push @INC, '.';
#
# this program gets a URL
# and fetches the data associated with that URL
# which is usually HTML data
# then it tokenizes the html so most of the
# HTML tags are displayed at the begining the line
#
#
# get the url the person entered on the HTML form
#
my $url = '';
$url=$cgi->param('url');
#
# if the URL is null set some default value
#
if ($url =~ /^ *$/ ) {
$url = 'http://miksup.100webspace.net';
}
#
# print the header stuff for a web page
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body link=\"blue\">";
print "<div style=\"background-color: #ffffff; color: rgb(0, 0, 0);\" id=\"tokyo\">";
#
# display the form to get the URL they want listed
#
print "<FORM action=\"perl_lwp.pl\" method=\"post\">";
print "<table><tr><td>URL:</td><td><INPUT name=\"url\" type=\"text\" size=\"160\"value=\"$url\"></td></tr>";
print "<tr><td> </td><td><INPUT type=\"submit\" value=\"ENTER\"></td></tr></table>";
print "</form>";
print "<p>";
#
# define the LWP stuff
#
use LWP::Simple;
#
# use LWP to read the URL from another remote web site
#
my $content = get $url;
#
# use die if the URL could not be defined
#
die "Couldn't get $url" unless defined $content;
#
# convert the RAW HTML to html we can display
#
$content_html=html_to_dhtml($content);
#
# to make it cleaner put a number of selected tags
#tags on at the begining of a line. so
# a <p> tag is displayed as
# <br><p>
#
# it would have been simpler to call the function
# $content_html=mikes_fix_html($content_html);
# but as an example on how to use the require function
# i did this.
# also because we are requiring it the $content_html
# cant be defined with 'my $content_html'
#
require 'perl_lwp_edits.pl';
#
# display the RAW HTML
#
print "The HTML from web page<blockquote><a href=\"".$url,"\">$url</a></blockquote>";
print "<table width=\"100%\" style=\"color: rgb(0, 0, 0);\">";
print "<tr>";
print "<td width=\"10%\">";
print " ";
print "</td>";
print "<td width=\"90%\">";
print "$content_html";
print "</td>";
print "</tr>";
print "</table>";
print "</div>";
#
# how display the actual HTML
# which depending on how they coded it
# may or may not look like the actual HTML
#
print "Now this web page is displayed as defined by its HTML<blockquote><a href=\"".$url,"\">$url</a></blockquote>";
print "$content";