Mailing List Archive

a minor feature suggestion: special perlvar @&
(while wrestling with the approximate matching package...)

What would you think of an array called &, that is, '@&' (maybe
@SUB_MATCHES after 'use English'?) Read-only, would contain after a
regexp match all the (submatches). Sort of a shadow implementation of
the $1, $2, $3, ... like this: $&[0] eq $1, $&[1] eq $2, $&[2] eq $3,
... Advantage over the $1, $2, $3, ...: when constructing regexps in
run-time one would not need to track the number of () submatch
constructs but use $#& instead. Exempli gratia: picking the 2nd,3rd,
and the last submatches to be, say, concatenated and translated into
lowercase would be:

lc("@&[1,2,$#&]")

Or finding out the length of all the "even" submatches:

length("@&[map{2*$_}1..($#&-1)/2]")

This is, by strange coincidence, exactly what I have to do when
inspecting for 'insertions' while matching approximately...

++jhi;

P.S. I know, Tom thinks that an array called & would be Offensive
Line Noise :-)
Re: a minor feature suggestion: special perlvar @& [ In reply to ]
jhi> length("@&[map{2*$_}1..($#&-1)/2]")

Oops. Make that

length("@&[map{$_-1}map{2*$_}1..$#&/2]")

(you did spot the mistake, didn't you? :-)

++jhi;

P.S. In case someone gets again afraid by Perl's featurism and stability:
I am, again, as usual, only daydreaming and brainstorming...
Re: a minor feature suggestion: special perlvar @& [ In reply to ]
>From: Jarkko Hietaniemi <jhi@epsilon.hut.fi>
>(while wrestling with the approximate matching package...)
>What would you think of an array called &, that is, '@&' (maybe
>@SUB_MATCHES after 'use English'?) Read-only, would contain after a
>regexp match all the (submatches). Sort of a shadow implementation of
>the $1, $2, $3, ... like this: $&[0] eq $1, $&[1] eq $2, $&[2] eq $3,
>... Advantage over the $1, $2, $3, ...: when constructing regexps in
>run-time one would not need to track the number of () submatch
>constructs but use $#& instead. Exempli gratia: picking the 2nd,3rd,
>and the last submatches to be, say, concatenated and translated into
>lowercase would be:
> lc("@&[1,2,$#&]")
>Or finding out the length of all the "even" submatches:
> length("@&[map{2*$_}1..($#&-1)/2]")
>This is, by strange coincidence, exactly what I have to do when
>inspecting for 'insertions' while matching approximately...

Why bother. You can alreat get that just by saying:

@SUB_MATCHES = ($x =~ /..../);

Ther eis no nedd for a magic array as any array will do.

--
Mark Biggar
mab@wdl.loral.com
Re: a minor feature suggestion: special perlvar @& [ In reply to ]
>
> Why bother. You can alreat get that just by saying:
>
> @SUB_MATCHES = ($x =~ /..../);
>
> Ther eis no nedd for a magic array as any array will do.
>
> --
> Mark Biggar
> mab@wdl.loral.com

Oops, I did it again, asked for something that Perl already does. :-)

++jhi;