On Tue, 29 Aug 2000 08:51:29 -0400, Mark-Jason Dominus wrote:
>There are many operations that would be simpler if there was
>a magic array that contained ($1, $2, $3, ...). If anyone wants to
>write an RFC on this, I will help.
Heh. I once complained about the lack of such an array, in
comp.lang.perl.misc, *years* ago.
My practical problem was something like this, in a translation program.
$phrase is one of many patterns in a table, to look for English phrases,
%translate contains the French translations. interpolate() is a sub that
fills in the parameters -- the numbers in the string):
$_ = "It is 5 past 10."
$phrase = 'it is (\d+) past (\d+)';
s/^$phrase/interpolate($translate{$phrase}, $1, $2)/ie;
The problem is that with variable patterns, you *don't know* how many
paren groups there are.
The solution they came upo with, was @+ and @-. I still can't work with
those. An array of matches, (e.g. @&) would be a lot easier. It could
also be a lot slower; see the discussion on $& for this. (mystery: how
can filling in $& be a lot slower than filling in $1?)
--
Bart.