- Using Perl with HAL -

  

 

 

 

 

Using Perl - Page 2

 

PERL to the Rescue

PERL is an invisible wonder. It is so pervasive on the web as to be unseen, unnoticed, and unrecognized. It is available on almost any computer, and within some reasonable limits, code written in PERL is extremely portable from one computer to another, across laptops and mainframes, across Windows, UNIX and MAC. Most web servers on the Internet make extensive use of PERL.

This is because, among other things, PERL is free, open source software with no limits placed on it’s use. It’s also because PERL is extremely powerful. And finally it’s because of something called CPAN, the Comprehensive Perl Archive Network. CPAN provides for a global, organized access to all things PERL.

Beyond PERL itself, documentation and so forth, CPAN also provides a central archival and distribution point for PERL modules. PERL Modules are blocks of PERL code that are tested, debugged and encapsulated so as to hide their complexity. They are freely available, and easy to use. They allow novice PERL users to leverage the talent and expertise of more experienced programmers, and to easily build programs that contain far more elegance and complexity than they could build themselves.

Mechanize & TokeParser PERL Modules

Two CPAN modules are of interest to our purpose.

Mechanize allows you to go to a URL and explore the site, following links by name, taking cookies, filling in forms and clicking "submit" buttons.

TokeParser is an HTML aware text parser. The initial examples in this document only use Mechanize, but for more complex tasks, TokeParser will become extremely valuable.

Mechanize takes a URL as an argument and returns the HTML text of the web page in a variable named {content}. Once we have the contents of the web page in a variable within our program, extracting the data we want becomes a matter of simple text manipulation.

Getting Started With PERL

The first thing you must do is download and install PERL. You can, of course, do this from CPAN, but a company named ActiveState has created a Windows Installer package for the less technical users that automates what would otherwise be a tedious process. All you need do is download the file .msi and then double-click on it. The installation will create a directory tree on your hard drive that contains the components of the program, starting with the top level C:\Perl directory. Note that immediately under C:\Perl is C:\Perl\lib where libraries are stored.

 

 

 

 

 

 

 

 

 

Sidebar

 

Testing PERL

Once you’ve installed PERL on your computer, you might wish to test it before trying anything more complex. To do so, open a DOS CMD window and cd C:\Perl. At the C:> prompt type the following:

C:\Perl>copy con hello.pl

print "Howdy!\n";

^Z

1 file(s) copied.

C:\Perl>perl hello.pl

Howdy!

C:\Perl>

If you get the shown response, Perl is working

Navigation

Introduction

Page 1

Page 2

Page 3

Page 4

Main Menu