Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
[Discipulus]: shmem the first time I was in germany I was so smart to learn by heart the address of the hostel: Einbahnstraße..
[Discipulus]: james28909 you are welcome
james28909 doesnt drink much alcohol
james28909 does enjoy blazing up though
james28909 also walks around hunting for his cell phone while using its flashlight function

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-05-20 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?