Dpuiu Perl: Difference between revisions

From Cbcb
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
* [http://en.wikipedia.org/wiki/Plain_Old_Documentation POD]; pod2html  pod2latex pod2man  pod2text  pod2usage
* [http://en.wikipedia.org/wiki/Plain_Old_Documentation POD]; pod2html  pod2latex pod2man  pod2text  pod2usage


= Comman options =
= In place editing =
* Edit a file in place: -i
* Edit a file in place: -i
   perl -i.bck script.pl xxx
   perl -i.bck script.pl xxx
   => xxx(new), xxx.bck(old)
   => xxx(new), xxx.bck(old)
= BEGIN/END blocks =
  perl -ane 'BEGIN { print "sum\n"}  END { print $sum,"\n" } $sum += $F[0]; '


= Regular Expressions =
= Regular Expressions =
Line 23: Line 26:
   perl -MLWP::Simple -e' print head "http://www.example.com"'
   perl -MLWP::Simple -e' print head "http://www.example.com"'
   perl -e 'use LWP::Simple; print head "http://www.example.com"'
   perl -e 'use LWP::Simple; print head "http://www.example.com"'
= Variables =
* $. : input line number

Revision as of 12:15, 4 November 2008

POD

  • POD; pod2html pod2latex pod2man pod2text pod2usage

In place editing

  • Edit a file in place: -i
 perl -i.bck script.pl xxx
 => xxx(new), xxx.bck(old)

BEGIN/END blocks

 perl -ane 'BEGIN { print "sum\n"}  END { print $sum,"\n" } $sum += $F[0]; '

Regular Expressions

  • Maximal match (default)
 echo $PERLLIB | perl -ane '/^(.+):/; print $1,"\n"'
  • Minimal match
 echo $PERLLIB | perl -ane '/^(.+?):/; print $1,"\n"'
 /fs/sz-user-supported/Linux-x86_64/lib

Search directories

  • -Idir : same as "use lib dir_name"
 default: /usr/include & /usr/lib/perl
 add dirs to PERLLIB 

Modules

  • -M moldule: same as "use module_name"
 perl -MLWP::Simple -e' print head "http://www.example.com"'
 perl -e 'use LWP::Simple; print head "http://www.example.com"'

Variables

  • $. : input line number