1. Chap 2 - Scalar Var
    1. Comparison Operators
      1. string
      2. numeric
    2. $input=<STDIN>;
    3. chmop and chop
    4. defined and undef
  2. Chap 3 - Lists and Arrays
    1. $#arrayname - last element entry
    2. (1,'a',1..4,2.5,qw(kasd sdf rr),@arr)
    3. list assignment or parallel assignment
      1. ($a, $b) = ($b, $a+$b)
    4. pop, push, shift, unshift
    5. foreach my $e (@arr) - !remember ()
    6. sort and reverse
    7. scalar and list CONTEXT
      1. $count=@arr
      2. use fake function scalar to force using a scalar context!
      3. chomp(@lines=<STDIN>); #read till ctrl+D and remove all linefeeds.
  3. Chap 4 - Subroutines
    1. sub my_add { my ($a, $b) = @_; if ($a>$b) {$a;} else {$b;} } &my_add(1,2);
    2. ALWAYS use ampersand (&)
  4. Chap 5 - Input and Output
    1. while(defined($line=<STDIO>)){print $line;} === while(<>){print;}
    2. print @a; vs print "@a";
    3. printf for formatted printing
    4. open FILE, ">>", "log" or die $!; print FILE "haha, err again!";
  5. Chap 6 - Hashes
    1. %h=("hello" => "salut", "thanks" => "merci");
    2. %h=('hello','salut',thanks','merci');
    3. while (($k,$v)=each %h){print $k.'=>'.$v;}
    4. modify, add, delete, exists, keys, values
    5. %ENV
  6. Chap 7 - Regex
    1. metacharacters
    2. quantifiers
    3. grouping
    4. alternatives
    5. character classes
    6. character classes shortcuts
    7. shortcuts negating
  7. Chap 8 - Matching with Regex
    1. //, m##,
    2. /i - case insensitive
    3. /s - let . match everything including \n
    4. /x - ignore \s
    5. anchors and word anchors - ^, $, \b, \B
    6. match vars - $1, $2, $3...
    7. noncapturing parentheses (?:hello)
    8. $`, $&, $'
    9. specific quantifiers
    10. perlrequick, perlretut, perlre
  8. Chap 9 - Text Processing
    1. s#pattern#string#gisx
    2. case shifting with \U, \L, \E, \u\L also available in double-quoted strings
    3. @a=split /pattern/, $s;
    4. $s=join $s, @a;
    5. non-greedy quantifiers vs. greedy quantifiers
      1. diff performance
      2. diff result in some cases
    6. /m for multi-line matching
      1. open F, $fn or die $!; $s=join '',<F>; $s=~s/^/$fn: /gm;
  9. Chap 10 - More Control Structures
    1. unless, untill
    2. expression modifiers
    3. a naked block provides a lexical var context
    4. elsif
    5. for==foreach
    6. last, next, redo
    7. ?:, and, or, &&, ||
  10. Chap 11 - Modules
    1. CPAN=Comprehensive Perl Archive Network
    2. perl -MCPAN -e shell
    3. import a module
      1. use File::BaseName;
      2. use File::BaseName ();
      3. use File::BaseName qw/ basename /;
    4. databases and DBI
  11. Chap 12 - File Tests
    1. -d, -e, -M
    2. if -r $file and -w _ is more efficient than if -r $file and -w $file
    3. my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,   $size, $atime, $mtime, $ctime, $blksize, $blocks)      = stat($filename);
  12. Chap 13 - Dir Operations
    1. chdir
    2. glob "*.pm"; === <"*.pm">;
    3. opendir, readdir, closedir
    4. unlink to remove files
    5. rename "old" "new"
    6. link and symlink
    7. mkdir and rmdir
    8. chown, chmod
  13. Chap 14 - Strings and Sorting
    1. find a sub string with index
    2. substr
    3. sprintf
    4. advanced sorting with sort subroutine @arr;
      1. %score={"R",100,"Z",90,"P",100}; @winners=sort by_score_and_name keys %score; sub by_score_and_name { $score{$b}<=>$score{$a} or $a cmp $b}
  14. Chap 15 - Smart Matching and given-when
  15. Chap 16 - Process Mgmt
    1. system - creates a new proc
    2. exec - replace the perl proc
    3. `` - enable capturing the output
      1. $result = `who`;
      2. @lines = `who`;
    4. %ENV
    5. piped open - open a concurrent child process
      1. open PS, 'ps aux|' or die $!; chomp(my @lines) = <PS>;
      2. open MAIL, '|mail yawen' or die "cannot pipe to mail: $!"; print MAIL "hi, i am you!"; close MAIL; die "non-zero return value: $?" if $?;
    6. defined($pid=fork) or die $!; unless($pid){ #Child process exec 'date'; die $!; } #Parent process waitpid($pid, 0);
      1. perlipc
    7. sending and receiving signals
      1. kill 2, $pid or die $!;
      2. warn "$pid is gone!" unless (kill 0, $pid);
    8. $$ for a random value
  16. Chap 17 - Advanced Techniques
    1. trapping errors with eval
      1. eval {EXPRESSION}
      2. $@ for the err msg
      3. eval $str; is dangeous
    2. advanced grep
      1. @odd_nu=grep{$_%2} 1..1000;
      2. @arr=grep{/$pattern/} <FILE>; or @arr=grep /$pattern/, <FILE>;
    3. map {&subr($_)} @arr;
    4. parentheses required in list slices
      1. $mtime=(stat $file)[9];
    5. array slices
      1. @new_arr=@arr[0,4,2,1]; - to pick and rearrange items in @arr to form @new_arr
    6. hash slices
      1. @three_scores=@hash_name{qw/ ralph ruby stef /}
  17. http://ishare.iask.sina.com.cn/f/5139414.html
  18. PERL=Practical Extraction and Report Language
  19. Perl is good for
    1. text processing
    2. sys admin
    3. ...as a glue language
    4. is a general-purpose language
  20. CPAN
  21. resources
    1. perldoc
    2. perlmonks
    3. orielly series
      1. learning perl
      2. intermediate perl
      3. mastering perl
      4. programming perl
      5. perl best practices
  22. tools
    1. vim, Komodo