Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • > Note that $_ within the closure refers to
    > this state object, not the original search
    > string. If you search on the state object,
    > however, it pretends that you wanted to
    > continue the search on the original string.

    What if I wanted to do something else to $_ ?

    Hmm... More precisely, I guess I'm wondering about two
    separate things here.

    1) What if I wanted to do something to what
       had been $_ before we were within the closure?

    2) What if I wanted to do something to the
     
    • By the time you get into a regex, you're always
      dealing with $_.  Even =~ behaves as a topicalizer
      for its right side.  So, while the $_ inside a
      closure is the search state object, it's always
      related intimately to the outer $_, which is always
      an alias for whatever you're currently searching.
      Any string operations on the inner $_ should be
      delegated to the original string.  Providing an
      explicit method to get at that string should be a
      no-brainer, though if you mess with the string,
      there's no guaran
      • > though if you mess with the string,
        > there's no guarantee that the regex
        > will continue to make sense.

        I kinda figured that would be the case. I was thinking
        of methods on strings or stringifiable objects which
        don't change the string. A trivial example might be
        getting the length of the target string, when the regex
        may not know the name of the variable containing the
        string to which is being applied.

        It sounds like it won't need to know, which sounds good!

        -matt