Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

/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 
    #       regcreset
  12. or download this
    # This is a convenient source of data to match against. (Plato's _The_
    $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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://269035]
Approved by Coruscate
Front-paged by Coruscate
[ambrus]: Like <c>{ package AnyEvent::Impl:: Prima; use Prima; sub io{ my($s,%r)=@_; Prima::File->new( file=>$r{fh},mask =>("w"eq$r{poll}? fe::Write():fe:: Read())|fe:: Exception,onRead =>$r{cb},onWrite =>$r{cb}, onException=>$r{cb }) } sub timer { ... } push @AnyEvent::REGI
[ambrus]: argh, too long, let me try on scratchpad
[Corion]: . o O ( I seem to have improved my skills of getting other people to write code for me )
[ambrus]: ambrus's scratchpad
[ambrus]: Also, I was wrong, apparently you have to support both periodic and one-shot timers in an AnyEvent backend
[Corion]: ambrus: That looks deceptively simple, but maybe that's simply all that's needed. Which would be great! I hope I get to test it tomorrow, thanks!!

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2016-12-08 12:43 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (141 votes). Check out past polls.