On 25 Sep 98, at 19:53, Jack Killpatrick wrote:

> Michael Stone hit the nail on the head:
> 
> Thanks much, Mike. This code worked and I now have it as the foundation of
> my script, surely to be reused in other places. Concise, neat, splendid.

I suggest that anyone who uses perl start to move into object-
oriented perl.

"We've all fallen into the trap of using cut-and-paste when we should 
have chosen do to define a higher-level abstraction, if only just a 
loop or subroutine.*  To be sure, some folks have gone to the 
opposite extreme of defining ever-growing mounds of higher-level 
abstractions when they should have used cut-and-paste. *  generally, 
though, most us need to think about using more abstraction rather 
than less."

(Caught somewhere in the middle are the people who have a balanced 
view of how much abstraction is good, but who jump the gun on writing 
their own abstractions when they should be reusing existing code.)*

* This is a form of False Laziness
* This is a form of False Hubris
* You guessed, this is False Impatience.  But if you're determined to 
reinvent the wheel, at least try to invent a better one.

--Larry Wall "Programming Perl" 2nd ed. page 277

I often tell the designers I work with that they should know html; it 
is not enought to just know how to use a wysiwyg.  I hate to see 
their belief in what is possible limited by their knowledge of a 
wysiwyg.

And yet here I suggest that you use the great perl modules.  Well, I 
would tell any perl programmer that before they use a module they 
should be able to write their own (and that's about where I am as I 
am in the transition to oo perl).

The use of the modules can greatly speed development of any 
application.  Rather than seek out the code to cut and paste, you 
just create an instance of the class. Of course, just as you need to 
learn a software program, you  need to learn the class you intend to 
use.  I remember people suggest that I use CGI.pm but I kept using 
cgi-lib.pl; I should have spent more time tyring to understand how to 
use CGI.pm.  But my argument is not about whether CGI.pm is better or 
worse than cgi-lib.pl.  Rather, it is about the benefits of using 
modules and an oo approach, imho.

Here is something I quickly wrote using LWP and some other modules:

http://www.rede.com/samples/example_lwp.html

That is plain html which has this ssi:
<!--#exec cgi="/cgi-bin/parser.cgi" -->

and then that ties into this cgi which is another instance of LWP
get_movie_review.cgi (see below)

and parser.cgi is:

#! /usr/local/bin/perl5 -w

use CGI;
use LWP::UserAgent;
use URI::URL;
use URI::Escape;
use strict;

use vars qw($q $ua $title $external_cgi $request $response $content $links @movies 
@sorted);

$title = "Recent U.S. Movie List from IMDB";
$external_cgi = "http://us.imdb.com/Recent/USA";

$q = new CGI;

$|++;

print $q->header();
$ua = new LWP::UserAgent;
$ua->agent("Charlotte/0.1 " . $ua->agent);
$request = new HTTP::Request('GET', $external_cgi);
$response = $ua->request($request);
$content = $response->content;

my @content=split(/\</,$content);
@movies = ();
for(@content) {
        chomp;
        if (/Title\?/) {
                /Title\?([^>]+)(.*)/;
                my $option = $1;
                my $movie = $2;
                $option =~ s/["><]+//g;
                $movie =~ s/["><]+//g;
                push(@movies,"<option value=\"$option\">$movie\n");
        }
        
}
@sorted = ();
@sorted = sort @movies;
print  qq|@sorted|;
######################### END ######################

get_movie_review.cgi

#! /usr/local/bin/perl5 -w

use LWP::Simple;
use URI::Escape;
use HTML::Parse;
use CGI;
use strict;

use vars qw($q $movie $movie_display $external_cgi $u_movie $data 
$title $body);

$q = new CGI;

$|++;

$title = "An Unauthorized Interface To Movie Review Query Engine -
http://www.mrqe.com/";

print $q->header();
print $q->start_html(
                                                -title=>"$title",
                                                -author=>'[EMAIL PROTECTED]',
                                                -meta=>{'keywords'=>'cgi oo lwp ',
                                                                'copyright'=>'GNU'},
                                                -BGCOLOR=>'white');

$movie = $q->param('movie') || "ronin";
$external_cgi = "http://www.mrqe.com/lookup?$movie";


$movie_display = uri_unescape($movie);
$movie_display =~ s/["\+]+/ /g;
# <base href="http://www.mrqe.com/">
print qq|
<div align="center">
<h1>Working on getting reviews for</h1>\n<p>\n<h2>$movie_display</h2>
<p>
<b>Please Wait </b>
|;

$data = get("$external_cgi");

$data =~ s/[\n\r\cM\t]+//g;
($body) = $data =~ /(<BODY[^>]+)/i;
if ($body) {
        $data =~ s/$body/<body/i;
}
$body =~ s/[<>]+//g;
print  qq|
<table border="1" width="80%" $body>
<tr><td>$data</td></tr>
</table>
<p>\n
|;

print qq|
        </div>
        <hr>
        <h2>Finished</h2>
        |;

print $q->end_html;
exit;
#############


____________________________________________________________________
--------------------------------------------------------------------
 Join The Web Consultants Association :  Register on our web site Now
Web Consultants Web Site : http://just4u.com/webconsultants
If you lose the instructions All subscription/unsubscribing can be done
directly from our website for all our lists.
---------------------------------------------------------------------

Reply via email to