Re: RFC 110 (v3) counting matches

[email protected] (Mark-Jason Dominus)
Newsgroups perl.perl6.language.regex
Message-ID <[email protected]>
> On Mon, 28 Aug 2000, Mark-Jason Dominus wrote:
> 
> > But there is no convenient way to run the loop once for each date and
> > split the dates into pieces:
> > 
> >         # WRONG
> >         while (($mo, $dy, $yr) = ($string =~ /(\d\d)-(\d\d)-(\d\d)/g)) {
> >           ...
> >         }
> 
> What I use in a script of mine is:
> 
>     while ($string =~ /(\d\d)-(\d\d)-(\d\d)/g) {
>         ($mo, $dy, $yr) = ($1, $2, $3);
>     }
> 
> Although this, of course, also requires that you know the number of
> backreferences. 

The real problem I was trying to discuss was not this particular
application.  I was trying to point out a larger problem, which is
that there are several regex features that are enabled or disabled
depending on what context the match is in, so that if you want one
scalar-context feature and one list-context feature at the same time,
there is no direct way to do it.

> Nicer would be to be able to assign from @matchdata or something
> like that :)

I agree.  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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.