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.:
at the end of the scope, if I printed Data::Dumper's Dumper \%+ I would get$x = 'fo ar!'; $y = '?foob obar ar';
$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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lexical %+ %- and more?
by TimToady (Parson) on Oct 22, 2008 at 17:56 UTC | |
|
Re: Lexical %+ %- and more?
by JavaFan (Canon) on Oct 22, 2008 at 11:41 UTC | |
by blazar (Canon) on Oct 22, 2008 at 13:38 UTC |