Perl
From Christoph's Personal Wiki
Perl is a dynamic programming language.
see: scripts for examples
Contents
Regex
see: Regular expression
Search and replace all "foo" with "bar" in filename
:
perl -i -pe 's/foo/bar/gi' filename
Modules
Search and download: http://search.cpan.org/
Installing
perl -MCPAN -e shell #Or, perl -MCPAN -e "install Example::Module"
My favourites
- Perl/Modules/Lingua
- DBI
- Math::Bezier
- WWW::Mechanize (see: [1])
- WWW::Search::PubMed (see: [2])
- WWW::Search::NCBI::PubMed
- MediaWiki
- mvs
Upgrade CPAN
% perl -MCPAN -e shell cpan>install Bundle::CPAN cpan>q
- Force CPAN to produce a list of all the modules that have updates and update them:
/usr/bin/perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
Perlrun
Here is an excerpt from 'man perlrun
' about the important command line switches used when doing perl one-liners.
-a turns on autosplit mode when used with a -n or -p. An implicit split command to the @F array is done as the first thing inside the implicit while loop produced by the -n or -p. perl -ane 'print pop(@F), "\n";' is equivalent to while (<>) { @F = split(' '); print pop(@F), "\n"; } An alternate delimiter may be specified using -F.
-e commandline may be used to enter one line of script. If -e is given, Perl will not look for a script filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.
-n causes Perl to assume the following loop around your script, which makes it iterate over filename arguments somewhat like sed -n or awk: while (<>) { ... # your script goes here } Note that the lines are not printed by default. See -p to have lines printed. If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves on to the next file.
-p causes Perl to assume the following loop around your script, which makes it iterate over filename arguments somewhat like sed: while (<>) { ... # your script goes here } continue { print or die "-p destination: $!\n"; } If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves on to the next file. Note that the lines are printed automatically. An error occuring during printing is treated as fatal. To suppress printing use the -n switch. A -p overrides a -n switch.
BioPerl
See: http://www.bioperl.org/wiki/Main_Page
See also
- Perl functions A-Z
- perlop — Perl operators
- CPANPLUS (aka CPAN++) — a more modern version of CPAN.pm
External links
- Perl version 5.8.8 documentation
- Perl regular expressions
- perlrequick — Perl regular expressions quick start
- perlretut — Perl regular expressions tutorial
- "Beginning Perl" — full book online (as PDFs).
- Perl/Python Phrasebook
- Text manipulation tools — from GNU/Linux Command-Line Tools Summary
- Mandriva Perl library packaging policy (wiki)
- wikipedia:Perl
- wikipedia:Plain Old Documentation (aka POD)
Resources/Books
- Minimal Perl: For UNIX and Linux People by Tim Maher. ISBN 1-9323-9450-8.
This article is curently a "stub". This means it is an incomplete article needing further elaboration.
I always welcome suggestions, comments, and criticism. If you have something to contribute to this site, please follow this link: Contributing Information. Thank you!