# 6.Perl

{% hint style="info" %}
We'll introduce Perl here. If you have no previous experience on either Perl or Python, we would recommend **Python** for you.
{% endhint %}

[Teaching Video](https://lu-lab.gitbook.io/training/getting-startted#learning-materials): Week III.5.Perl

## 1) Install Perl Modules

1. Install CPAN: [How to install CPAN modules](http://www.cpan.org/modules/INSTALL.html)
2. Install modules with cpan

usually you start cpan in your shell:

`# cpan`

and type

`install Statistics::Basic`

`install Statistics/LineFit.pm`

`install Math/Cephes.pm`

or in short form:

`cpan install Statistics::Basic`

`cpan install Statistics/LineFit.pm`

`cpan install Math/Cephes.pm`

### Recommended Modules

* Bioperl :[ installation guide](http://bioperl.org/INSTALL.html)
* Statistics::Basic

## 2) Examples

[**My Perl Scripts at github**](https://github.com/urluzhi/scripts/tree/master/MISC_scripts) **,** for instance:

* seqmanipulator.pl
* snp.pl
* TFtargets.pl
* export\_intron.pl
* siRNA-filter-NAR2008.pl

## 3) Tips

**Perl in command line**

```perl
perl -ne 's/aaa/ccc/;print $_' file.in
perl -p -i.bak -e 's/aaa/ccc/' file.in
perl -pi -e 's/aaa/ccc/' file.in
perl -n -e '@line=split(" ",$_);print $line[0] $line[1],"\n"' file.in
```

**Syntax checking**

perl -cw \*.pl

**Add perl5lib**

in .bashrc:

`export PERL5LIB=/home/john/my_perl_lib:/CVS/my_perl_lib`

**The state of a file**

```perl
use File::stat;
$sb = stat($filename);
print "$sb->size\n";
```

**In a subroutine**

`my $a = @_;`

is illegal to read the input. Must add ( ) to the variable, so it should be

`my ($a) = @_;`

## 4) Homework for Perl

1. Try to run [my favorite Perl ](https://github.com/lulab/training_book/tree/0bdf8eb0cfc3e102d3b063f833cc236ca050f8aa/part-i-basic-skills/5.python-or-perl.md#2-examples)scripts and install the modules needed.

## 5) Video

[@Youtube](https://youtu.be/2jOGbVfuyjA)

[@Bilibili](https://player.bilibili.com/player.html?aid=30590572\&cid=53393101\&page=1)
