Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Why are 5.10's named captures read only?

by blazar (Canon)
on Oct 20, 2008 at 12:02 UTC ( [id://718202]=note: print w/replies, xml ) Need Help??


in reply to Re: Why are 5.10's named captures read only?
in thread Why are 5.10's named captures read only?

ISTR (and would expect anyway) that in Perl 6 there's provision for all these kinda things, everything being an object, by means of suitable methods. I suppose that under Perl 5 you would expect yet another pair of special variables instead. But which ones? All of the good ones seem to be gone, and also many of the bad ones!!

Perhaps, since AFAICT %_ is always free, it may have been chosen to hold the named captures instead of %+, and %+ and %- to hold the info you need, for analogy with @+ and @-... Before posting I was also thinking that perhaps %- were free, but it's not the case: it is... "%+ on steroids..."

--
If you can't understand the incipit, then please check the IPB Campaign.

Replies are listed 'Best First'.
Re^3: Why are 5.10's named captures read only?
by JavaFan (Canon) on Oct 20, 2008 at 12:14 UTC
    There are a gazillion variables "free" to choice from, unless you insist on one-character punctuation variables. Frankly, I don't think you need a one-character punctuation variable for this, and
    %{^MATCH_OFFSETS}
    will do fine. Personally, I'd like the values being arrays of arrays, the inner arrays 2 elements, the index of the start of the match, and the index just after the end of the match. (that is, similar to @- and @+). The outer array will hold as many captures with that name there are, so if you have:
    "abc" =~ /(?<l>[a-z])(?<l>[a-z])(?<l>[a-z])/
    the result is:
    %{^MATCH_OFFSETS} = ('l' => [[0, 1], [1, 2], [2. 3]]);

    I'm also pretty sure that if someone write a patch, it will be added to Perl.

      I personally believe it's clear enough that I don't insist but would certainly like... one-character punctuation variables which are nice, too! ;) I fully second the rest of your suggestion, BTW.

      If %- were not taken, I would have expected it to hold that kind of info. Methods would be the best thing though... I'm playing more and more with autobox but I know it doesn't fit too well in Perl 5's like typical mindset. (Apart the fact that its very docs warn about it not being real autoboxing!) And I don't know how would it square playing with such special variables as the ones we're discussing here...

      --
      If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://718202]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-24 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found