Perl
Introduction
Perl was developed by Larry Wall in 1987 as a general scripting
language. Perl 5 comes with most Linux operating systems. We have not
used Perl 6 in Bristol yet.
Documentation
See www.perl.org and googling a
specific query will often turn up a suitable solution.
Initialisation
A perl script should start with
#!/usr/bin/perl
Other versions of perl can be provided on request.
Version
[pavo]rahm: perl -version
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
Testing
Does your program run?
Usage
You can write a program or perl script by putting '#!/usr/bin/perl' on
the first line followed by commands in the Perl language.
Or you can use 'perl one liners', in the example below, column 2 (which is the the third column as Perl counts from 0) will be printed from the multicolum text file data.raw.
cat data.raw | perl -lane 'print $F[2]'
in the example below, all occurances of 'fudge' will be replaced by
'nougat' in the file sweets.txt.
perl -wpi -e 's/fudge/nougat/' sweets.txt
Author and References
The author of Perl is Larry Wall, and the three classic references are:
- Learning Perl by Randal L. Schwartz, brian d foy and Tom Phoenix
- Programming Perl: Unmatched power for text processing and scripting by Tom Christiansen, brian d foy, Larry Wall and Jon Orwant.
- Perl Cookbook by Tom Christiansen and Nathan Torkington
Copies of these books should be in the PhD student room.
Related Software
CPAN allows you to your own versions of Perl modules similar to the
pip command for Python. To install the Perl Module
'Astro::XSPEC::TableModel' then you would type 'cpan', and at the cpan
prompt 'install Astro::XSPEC::TableModel' as below:
rahm[pavo]rahm: cpan
Terminal does not support AddHistory.
cpan shell -- CPAN exploration and modules installation (v2.14)
Enter 'h' for help.
cpan[1]> install Astro::XSPEC::TableModel
CPAN: Storable loaded ok (v2.20)
Reading '/homeb/rahm/.cpan/Metadata'
Database was generated on Mon, 12 Sep 2016 10:29:02 GMT
Astro::XSPEC::TableModel is up to date (0.01).
Rhys Morris
Last modified: Monday, 12 September 2016