What kind of "interaction" are you intending to perform?
There are a number of modules on CPAN that are OO, such as
CGI.pm, DBI, or LWP and many others, and these can "interact"
by definition, though not without some effort on the part of
the programmer.
Interaction between modules is usually by design, and
as such, you can't really expect two modules written by two
different people for two different purposes to interact
spontaneously. They may be compatible, but it is in the program
that you write where the interaction occurs.
A good example of interaction is the
LWP system, the Web
"browser" library for Perl. To implement this, there are
a variety of objects which are used to represent everything
from a server connection (HTTP::Request) through to a URL
(URI), and many things inbetween. The library is very
comprehensive, and highly abstracted, so if
LWP
is too confusing, you can always use
LWP::Simple
which makes it a snap to 'get' Web pages.
Perhaps some sample code would better illustrate this. This
example grabs all the links from the Perl Monks page,
something that
HTML::LinkExtor does quite well,
so this is for educational purposes only:
#!/usr/bin/perl -w
use strict;
use HTML::Parser;
use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;
use URI;
# Create a LWP::UserAgent object which can be used to fetch pages
my $agent = new LWP::UserAgent();
# Create a URI, which represents a location on the WWW
my $uri = new URI ("http://www.perlmonks.com/");
# Create a HTML::Parser, used to process the HTML
my $parser = new HTML::Parser (
api_version => 3,
start_h => [ \&Start, 'tagname,attr' ],
);
# Define a behavior, used by HTML::Parser when it encounters
# the "start" of a tag (i.e. a declaration like '<X>', where
# the tagname would be 'x', as it is always passed as lower-case)
sub Start
{
my ($tagname,$attr) = @_;
if ($tagname eq 'a')
{
print "$tagname href=$attr->{href}\n";
}
}
# Make a download request for the page, which is requesting
# a 'GET' of the URL specified earlier
my $request = new HTTP::Request ( GET => $uri->as_string() );
# Tell the LWP::UserAgent to process this request, and
# capture the response.
my $response = $agent->request ($request);
# Feed the response to the HTML::Parser, which because of
# the customized 'Start' function, will do something useful.
$parser->parse ($response->content());
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.