develooper Front page | perl.perl6.language.regex | Postings from August 2000

Re: RFC 110 (v3) counting matches

Thread Previous | Thread Next
From:
Philip Newton
Date:
August 29, 2000 05:47
Subject:
Re: RFC 110 (v3) counting matches
Message ID:
Pine.LNX.4.04.10008290802040.23093-100000@ficus.frogspace.net
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 <newton@newton.digitalspace.net>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About