User:Feixie/Perl/Mastering Perl

Read <>

Advanced Regular Expressions

 * Compiled RE: eval { qr/$pattern/ };
 * Capturing group: $&, $1, .. $N; @-, @+;
 * option:
 * inline option: (?imsx:PATTERN)
 * qr/pattern/i; apply to all patterns
 * qr/(?-i:pattern)/
 * Nocapturing grouping: (?:Pattern)
 * Readable RE: /x flag; (?#Comments)
 * Global match: /g flag; my $num = = /pattern/g;
 * pos: can be a left value, every string has a pos on it.
 * Global Match Anchors: \G disables "floating"./c flag disables resetting pos.
 * Lookarounds:
 * positive/negetive lookahead/lookbehind: (?=p ?!p ?<=p ?<!p);
 * asserting won't consume/match string, but it may changes the match pos. It is based on pos.
 * Look-around assertions are zero width patterns which match a specific pattern without including it in $& . Positive assertions match when their subpattern matches, negative assertions match when their subpattern fails. Look-behind matches text up to the current match position, look-ahead matches text following the current match position.

types of variables
our $var1 = "b"; sub func{print $var1;} my $var1 = "a"; func;                     # print global "b" {local $var1 = "c";func;} # print local "c" our $var1; print $var1;                # output global "b"
 * package variable It is in symbol table.
 * lexical variable not in symbol table, does not have type glob. just like auto variables in C.
 * local variable It is also in symbol table of packages. The difference is that its scope is local (from where it declares to block end). But it do jump into functions in its scope which is different from lexical variable.

import block/module
package C; sub import { my $pkg = shift; my $callerpkg = caller(0); *{"$callerpkg\::$_"} = *{"$pkg\::$_"} foreach @_; }
 * do do block/expr execute sub script. do expr = eval 'cat expr'.
 * require require expr = do expr only once.
 * use use module list = BEGIN{require module;module->import(list);}.
 * import perl predefined function to import var/func from module to application after do the module.
 * caller caller expr, for tracing call stack at several levels.
 * 1) simple version of Export.
 * 1) use strict; # should not use strict

1;