Re: RFC 110 (v3) counting matches
[email protected] (Jonathan Scott Duff)
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Aug 28, 2000 at 05:40:11PM -0000, Perl6 RFC Librarian wrote: > =head1 TITLE > > counting matches > =head1 DESCRIPTION > > Have you ever wanted to count the number of matches of a patten? s///g > returns the number of matches it finds. m//g just returns 1 for matching. > Counts can be made using s//$&/g but this is wastefull, or by putting some > counting loop round a m//g. But this all seams rather messy. Don't forget to mention the canonical way to do it now: $count = () =~ /pattern/g; And why you feel that an option to m// is better. > m//gt (or m//t see below) would be defined to do the match, and return the > count of matches, this leaves all existing uses consistent and unaffected. > /t is suggested for "counT", as /c is already taken. I'd almost suggest that the existing /c be renamed so that you could use it for counting but that would cause much grief I'm sure :-) > Relationship of m//t and m//g - there are two possibilities, my original: > > m//gt, where /t adds counting to a group match (/t without /g would just > return 0 or 1). However \G loses its meaning. > > The Alternative By Uri : > > m//t and m//g are mutually exclusive and m//gt should be regarded as an error. What does m//c do now? It doesn't seem to make much sense without /g. I wonder why the no-reset global option wasn't called /G instead of /gc Someone care to enlighten me before I get up the gumption to RFC it? -Scott -- Jonathan Scott Duff [email protected]