- or download this
$BIG_REGEX = " ... ";
sub do_something {
...
do_something(); # the expression is compiled and fixed into place
do_something(); # the compiled expression is directly re-used
- or download this
$HUGE_REGEX = " ... ";
sub do_it {
...
$HUGE_REGEX = " !!! ";
do_it(); # the string changed so the regex is recompiled.
do_it(); # the new regex re-used.
- or download this
# I need a better way to phrase this. Ideas?
$BIGGER_REGEX = qr/ ... /; # The contents of qr// are a constant expre
+ssion so are compiled at compile-time.
...
# occurs now.
$BIGGER_REGEX = qr/ !!! /;
do_it_again(); # Like before, a pre-compiled regex is used directly. N
+othing special happens.
- or download this
$data =~ m/[spectal]{9}/;
# Match against $data
# match(/"[spectal]{9}"/)
- or download this
$re = "[spectal]{9}";
$data =~ $re;
# match()
...
# match()
# regcomp() # Compile the expression
# regcreset
- or download this
$qr = qr/[spectal]{9}/; # This was compiled during BEGIN{} and has no
+runtime effect.
$data =~ $qr;
...
# match()
# regcomp() # Re-use the expression
# regcreset
- or download this
$re = '[spectal]{9}';
$qr = qr/$re/; # Compile the expression
# qr()
...
# match()
# regcomp() # Re-use the expression
# regcreset
- or download this
$qr_a = qr/\w/; # Pre-compiled during BEGIN {}
$qr_b = qr/\d/; # Pre-compiled during BEGIN {}
...
# match()
# regcomp() # Compile the expression
# regcreset
- or download this
$re = '[spectal]{9}';
$data =~ m/$re/o;
# match()
# regcomp() # Compile the expression and remove this step
# regcreset
- or download this
$re = '[spectal]{9}';
$qr = qr/$re/o;
# qr()
...
# qr()
# regcomp() # Re-use the expression
# regcreset
- or download this
$qr = ...
$data =~ m/$qr/o;
# match()
# regcomp() # Associate the precompiled expression and remove this
+step
# regcreset
- or download this
# This is a convenient source of data to match against. (Plato's _The_
+Republic_)
$data = q[I WENT down yesterday to the Piraeus with Glaucon the son of
+ Ariston,
that I might offer up my prayers to the goddess; and also be
+cause I
...
# If the /o flag is added onto /$qr/ then that expression becomes fore
+ver bound to
# whatever value $qr contained at the time it was first executed. It t
+urns out that /o
# works by having the regcomp() operation remove itself from the execu
+ting program.