6.Perl

We'll introduce Perl here. If you have no previous experience on either Perl or Python, we would recommend Python for you.

Teaching Video: Week III.5.Perl

1) Install Perl Modules

  1. 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

2) Examples

My Perl Scripts at github , for instance:

  • seqmanipulator.pl

  • snp.pl

  • TFtargets.pl

  • export_intron.pl

  • siRNA-filter-NAR2008.pl

3) Tips

Perl in command line

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

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 scripts and install the modules needed.

5) Video

@Youtube

@Bilibili