Richard's Perl Step 51
Modules
Perl Modules can be downloaded from CPAN, which has all Perl module downloads. How to install modules? (simple for Windows: copy to c:\perl\lib\)
Tree::DAG_Node, CPAN module download (for this module), and a tutorial.
Math::MatrixReal, CPAN module download (for this module), very useful for matrix calculation.
LWP - The World-Wide Web library for Perl, for the latest Perl download, you do not need to install this module anymore.
A book online Perl & LWP. Found some tutorials on the web...
libwww-perl: First a request object is created and configured. This object is then passed to a server and we get a response object in return that we can examine. A request is always independent of any previous requests, i.e. the service is stateless. The same simple model is used for any kind of service we want to access.
For example, if we want to fetch a document from a remote file server, then we send it a request that contains a name for that document and the response will contain the document itself.
- Tutorial 1 (away from site), lwptut from CPAN.
- example000.txt, wait for key press, and get key press.
- example001.txt, LWP::Simple, simple get function to get a page at a URL.
- A simple one-liner, to get the page at URL, and output to STDOUT, more for debugging etc.... perl -MLWP::Simple -e "getprint 'http://yahoo.com'"
- example002.txt, LWP::Simple don't support cookies or authorization; don't support header lines in request and response. We need LWP::UserAgent and HTTP::Response.
- We can add query strings to the request by adding a list of key-value pairs after the URL, like so ... $response = $browser->get( $url, $key1, $value1, $key2, $value2, ... ); or can use array if there are many key-value pairs.
- A default LWP::UserAgent object acts like a browser with its cookies support turned off. There are various ways of turning it on, by setting its cookie_jar attribute.
- Many HTML forms send data to their server using an HTTP POST request, we need post method (can use same method to send headers and post), refer to tutorial 1 link above. I have not done example.
- Many HTML forms use GET method (default method for form), refer to this example003.txt (for Vista, must run from cmd window). Need to know which method the form of a website uses, also need to know if the website block this kind of programs. Also need to know the file name at the form action field... example004.txt (for Vista, must run from cmd window).
- The URI class provides all sorts of methods for accessing and modifying parts of URLs. One usage is for absolute URL, example005.txt.
- Tutorial 2 (away from site).