--- Using perl modules --------------------------------------------- * CPAN : thousands of perl packages for whatever you need * some come standard with perl; see perldoc.com's listing, i.e. at perldoc.com/perl5.8.0/lib.html * others you need to install, either by 1) download, unpack foo.tar.gz or foo.zip unix: "wget http:/......./foo.tar.gz; tar zxf foo.tar.gz" then "perl Makefile.pm; make; make install" 2) "perl -MCPAN -e shell" then "install Some::Package" - does it all * see instructions on page 236 of text. * For the long list, see http://theoryx5.uwinnipeg.ca/CPAN/by-name/ * To use a module, look at its documentation (perldoc.com or cpan.org) and follow examples. * New notation: $obj->method('argument1', 'argument2', ...); * This is similar to array de-reference : $ptr->[0] hash de-reference : $ptr->{name} only now we're calling a subroutine that's attached to a reference. (This is actually "object oriented programming"; we'll do more with this later.) * More new notation: use This::That; really means to find and load the file This/That.pm from one of the standard places, listed in the @INC array. This can be either in a system library, or in the local directory. Loading the .pm (perl module) file give you access to new subroutines and variables - the details vary from module to module. To see @INC, type perl -e 'print "@INC"' A variable named "our $table;" in module This:That has as its full name $This::That::table Examples: -- cut here ------------------ #!/usr/bin/perl -w use Acme::Bleach; print "Hi there. Are we having fun?\n"; # Try it a few times, then look at source file ... -- cut here ------------------ #!/usr/bin/perl -w use LWP::Simple; my $page = get('http://www.marlboro.edu'); print $page; # This is in libwww-perl, which you can install via "Bundle::LWP" # See http://theoryx5.uwinnipeg.ca/CPAN/data/libwww-perl/ # You could then look for links, do another get() to fetch some other # page, and so on. Web crawling robots, anyone? -- cut here ------------------ #!/usr/bin/perl -w use Math::BigInt; my $x = Math::BigInt->new('12345678901234567890'); print $x; print $x*$x; # Can you say "big integers"? -- cut here ------------------ use Text::Roman; print roman(123); # This one isn't installed on cs.marlboro.edu yet; # figured I'd do it in class. # (1) find it # (2) download it # (3) install it # # or # # perl -MCPAN -e shell # cpan> install Text::Roman # # and (if it all works) watch it do everything. # (Warning: setting the -MCPAN up the first time can be tricky.) --------------------- Others? Text::BarGraph (many other Text::... thingies.) Games::Battleship (I haven't looked at it...) Crypt::Blowfish; (Got a secret?) Inline::C; (*really* cool - embed other languages in your perl...) Algorith::FastPermute; (loop over permutations) Lingua::EN::AdressParse; (figure out parts of an address) Acme::Lingua::Pirate::Perl (for programming on September 19th. Yes, that really is "International Talk Like a Pirate Day". Go figure.) and so on ...