Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

/o is dead, long live qr//!

by diotalevi (Canon)
on Jun 25, 2003 at 22:05 UTC ( #269035=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. 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
    
  2. 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.
    
  3. 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.
    
  4. or download this
    $data =~ m/[spectal]{9}/;
    
    # Match against $data
    # match(/"[spectal]{9}"/)
    
  5. or download this
    $re = "[spectal]{9}";
    $data =~ $re;
    # match()
    ...
    # match()
    #    regcomp() # Compile the expression
    #       regcreset
    
  6. 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
    
  7. or download this
    $re = '[spectal]{9}';
    $qr = qr/$re/; # Compile the expression
    # qr()
    ...
    # match()
    #    regcomp() # Re-use the expression
    #       regcreset
    
  8. 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
    
  9. or download this
    $re = '[spectal]{9}';
    $data =~ m/$re/o;
    # match()
    #    regcomp() # Compile the expression and remove this step
    #       regcreset
    
  10. or download this
    $re = '[spectal]{9}';
    $qr = qr/$re/o;
    # qr()
    ...
    # qr()
    #   regcomp() # Re-use the expression
    #      regcreset 
    
  11. or download this
    $qr = ...
    $data =~ m/$qr/o;
    # match()
    #    regcomp() # Associate the precompiled expression and remove this 
    +step
    #       regcreset
    
  12. 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.
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://269035]
Approved by Coruscate
Front-paged by Coruscate
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-20 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls