WalaWiki content from p1k3.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

48 lines
1.5 KiB

WareLogging, PerlCode, RegularExpressions.
* http://www.pcre.org/
* perldoc: [http://perldoc.perl.org/perlreref.html perlreref] - RegEx reference
* MasteringRegularExpressions
Little RegEx tricks:
# Stuff in parentheses is slurped into the elements of @results
@results = $string =~ m/stuff, (more stuff), and (some other stuff)/;
# Here, $result is forced into list context and so contains (more stuff).
# Without parentheses, it would just contain 1 or 0, depending on the pattern match.
($result) = $string =~ m/stuff, (more stuff), and some other stuff/;
Store a regex:
$re = qr/whatever/;
= a thing which has recently bitten me =
When using s///x, keep in mind that whitespace continues to be significant in your substitution, which is after all a string.
For example, this will be fine:
$block =~ s/([^"\n]) # not a double-quote or newline
\n # end-of-line
([^\n]) # not a newline
/$1$newlines{$key}$2/xgs;
While this will be all kinds of problematic:
$block =~ s/([^"\n]) # not a double-quote or newline
\n # end-of-line
([^\n]) # not a newline
/$1
$newlines{$key}
$2
/xgs;
Incidentally, I think this is better written as:
$block =~ s/(?<=[^"\n]) # not a double-quote or newline
\n # end-of-line
(?=[^\n]) # not a newline
/$newlines{$key}/xgs;