Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

That's really cool, but I'm confused as to why it works. From perlre about (??{ code }):

This is a "postponed" regular subexpression. The "code" is evaluated at run time, at the moment this subexpression may match. The result of evaluation is considered as a regular expression and matched as if it were inserted instead of this construct.

Maybe I'm thrown by the "matched as if it were inserted" part when what's being inserted is a regular expression -- if it were just inserted, I don't understand why your approach works different from just putting the subexpression in directly. It looks like it's being evaluated somehow "separately" from the rest of the regular expression, which I didn't expect given the doc. I don't know if that makes sense, but this code sample illustrates where I'm thrown:

my $re = qr/(.)\1*/; @matches = $string =~ m/($re)/g; print "@matches\n"; # x x x x 5 5 5 5 6 6 x x x x @matches = $string =~ m/((??{$re}))/g; print "@matches\n"; # xx 55 6 xx

Could you please help me understand what's really going on that's different between these two cases?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re^2: Elegant way to split into sequences of identical chars? by xdg
in thread Elegant way to split into sequences of identical chars? by pKai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-03-28 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found