Perl: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
 
(33 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
*[http://cpan.org/ CPAN]: Comprehensive Perl Archive Network
*[http://www.perl.org/ The Perl Directory] - perl.org
**[http://perldoc.perl.org/ Perl documentation]
**[http://www.perldoc.com/perl5.8.0/pod/perlintro.html Introduction to Perl]
**[http://faq.perl.org/ FAQs]
*[http://www.perl.com/ Perl.com]
**[http://www.perl.com/pub/q/faqs FAQs]
*[http://www.cs.cmu.edu/People/rgs/pl-exp-op.html Perl 4 operators]
*[http://use.perl.org/~ziggy/journal/26131 Manipulexity and Whipuptitude]
*[http://www.perl.com/pub/a/2006/01/12/what_is_perl_6.html perl.com: What Is Perl 6]
*[http://stuff.mit.edu/iap/perl/ SIPB IAP 2006 Perl Programming]
*[http://perldoc.perl.org/index-language.html Language reference] - perldoc.perl.com
**[http://perldoc.perl.org/perlsyn.html perlsyn]
*[http://stein.cshl.org/genome_informatics/ Genome Informatics lectures] by Lincoln Stein
**[http://stein.cshl.org/cgi-bin/perlref Perl Function Documentation] - lookup function description by its name
==Recipes==
*[http://sedition.com/perl/code-index.html Code index]
*[http://www.perlcircus.org/ Perl Circus] - Perl Tricks, Tips And Traps
*[[Perl/Closures|Closures]]
*[[Perl/Closures|Closures]]
*[[Perl/Modules|Modules]]
*[http://sial.org/howto/perl/ Perl howto] @ sial.org
*[http://www.perl.com/pub/a/2006/03/02/ajax_and_perl.html Using Ajax from Perl] @ perl.com
*[http://www.perl.com/pub/a/2005/07/14/bestpractices.html Ten Essential Development Practices] @ perl.com
==Toolkits==
*[[Perl/CGI|CGI]]
*[[Perl/CGI|CGI]]
**[http://perldoc.perl.org/CGI.html CGI - perldoc.perl.org]
**[http://search.cpan.org/dist/CGI.pm/ CGI.pm - Lincoln D. Stein]
**[http://search.cpan.org/~markstos/CGI-Application-4.05/lib/CGI/Application.pm CGI::Application] - Framework for building reusable web-applications
**[http://www.perl.com/pub/a/2001/06/05/cgi.html Using CGI::Application]
*[[Perl/DBI|DBI]]
*[[BioPerl]]


==Packages==
===Web development frameworks===
 
*[http://www.catalystframework.org/ Catalyst]
use Module();
**[http://www.perl.com/pub/a/2005/06/02/catalyst.html perl.com: Catalyst]
is equivalent to
*[http://jifty.org/ Jifty]
BEGIN { require "Module.pm"; }
**[http://stuff.mit.edu/iap/webapps/ MIT IAP 2007 class]
and
require Module;
 
require "Cards/Poker.pm";          # runtime load
require Cards::Poker;              # ".pm" assumed; same as previous
use Cards::Poker;                  # compile-time load, implicit import of package
 
All programs are in package main until they use a package statement to change this.
package Alpha;
$name = "first";
package Omega;
$name = "last";
package main;
print "Alpha is $Alpha::name, Omega is $Omega::name.\n";
Output:
Alpha is first, Omega is last.
 
Module example
1    package Cards::Poker;
2    use Exporter;
3    @ISA = ("Exporter");
4    @EXPORT = qw(&shuffle @card_deck);
5    @card_deck = ( );                      # initialize globals
6    sub shuffle { }                        # fill-in definition later
7    1;    # last expression is the overall value of module - must be true
 
*Line 1
Typically, a module first switches to a particular package so that it has its own place for global variables and functions, one that won't conflict with that of another program. This package name must be written exactly as in the corresponding use statement when the module is loaded.
*Line 2 loads in the Exporter module, which manages your module's public interface
*Line 3 initializes the special, per-package array @ISA to contain the word "Exporter".  When a user says use Cards::Poker, Perl implicitly calls a special method, Cards::Poker->import( ). You don't have an import method in your package, because the Exporter package does, and you're inheriting from it because of the assignment to @ISA (is a).
*Line 4 assigns the list ('&shuffle', '@card_deck') to the special, per-package array @EXPORT. When someone imports this module, variables and functions listed in that array are aliased into the caller's own package.
*Lines 5 and 6 set up the package global variables and functions to be exported.
 
===Other kinds of library files===
 
A library is a collection of loosely related functions designed to be used by other programs. It lacks the rigorous semantics of a Perl module. The file extension .pl indicates that it's a Perl library file.
 
Perl libraries—or in fact, any arbitrary file with Perl code in it—can be loaded in using do "file.pl" or with require "file.pl". The latter is preferred in most situations, because unlike do, require does implicit error checking.
 
Another advantage of require is that it keeps track of which files have already been loaded in the global hash %INC. It doesn't reload the file if %INC indicates that the file has already been read.
 
===Finding modules and libraries===
 
*@INC is an array that Perl uses to determine the directories to search for libraries and modules.
*%INC, which is a list of the actual modules Perl has loaded from the environment.
 
Example:
perl -e "print @INC";
and
foreach $key (sort keys(%INC)) {
    print "$key => $INC{$key}\n";
}


Modifying @INC
===GUI===
*[http://www.perl.com/pub/a/2001/03/gui.html Writing GUI Applications in Perl/Tk]
*[http://www.perl.com/pub/a/2001/09/12/wxtutorial1.html wxPerl: Another GUI for Perl]


Easiest way:
==Books==
use lib "C:\\MyModuleDirectory";
*[http://www.cs.cf.ac.uk/Dave/PERL/perl_caller.html Practical Perl Programming]
use MyModule;
*[http://en.wikibooks.org/wiki/Programming:Perl Programming:Perl] - a wikibook
*[http://freecomputerbooks.com/langPerlBooks.html Misc Perl books online]
*[http://www.unix.org.ua/perl/ Введение в Perl]

Latest revision as of 13:45, 13 April 2007