Re: RFC 110 (v3) counting matches
[email protected] (Philip Newton)
| 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. Nicer would be to be able to assign from @matchdata or
something like that :)
Cheers,
Philip
--
Philip Newton <[email protected]>