This is basically a repost of the last part of a reply of mine which appearently went unnoticed and anyway didn't get any answer: indeed it went slightly OT WRT the main thread.

So we have named captures and it's not much time since we do, but I already ask for them not to be read-only: what people tell me basically is that there are implementation details that force them to be instead. Now I go one step further so this may well be taken as sci-fi, but nevertheless I think it exposes an interesting idea: from 5.10 onward we have a lexical $_ so I wonder whether we could have lexical %+ and %- such that:

Thus one may have the following example (which explains the whole thing better than many abstract descriptions...) working as naively expected:

{ my %+; doit if $x ~~ / (?<x1> \w+)\s+(?<x2> \w+) /x and $y ~~ / (?<y1> \w+)\s+(?<y2> \w+) /x and $+{x1} . $+{y2} eq $+{y1} . $+{x2}; }

Assuming e.g.:

$x = 'fo ar!'; $y = '?foob obar ar';
at the end of the scope, if I printed Data::Dumper's Dumper \%+ I would get

$VAR1 = { 'y1' => 'foob', 'x2' => 'ar', 'y2' => 'obar', 'x1' => 'fo' };

Please don't point out that wrt the example above there are tons of other WTDI: it's obvious that there are - we're talking about Perl anyway! I just think we could have one more, and with a very clear syntax too. Also, the idea sprang in the context of that other thread dealing with %+ and %- but there may be other special variables that may allow a lexical incarnation with a modified semantics associated to to it.

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

In reply to Lexical %+ %- and more? by blazar

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.