develooper Front page | perl.perl6.language | Postings from May 2005

Re: Numification of captured match

Thread Previous | Thread Next
From:
Jonathan Scott Duff
Date:
May 12, 2005 21:33
Subject:
Re: Numification of captured match
Message ID:
20050513043330.GB22659@pobox.com
On Thu, May 12, 2005 at 08:10:42PM -0700, Larry Wall wrote:
> On Thu, May 12, 2005 at 02:55:36PM -0500, Patrick R. Michaud wrote:
> : My suggestion is that a match object in numeric context is the
> : same as evaluating its string value in a numeric context.  If
> : we need a way to find out the number of match repetitions (what
> : the numeric context was intended to provide), it might be better
> : done with an explicit C<.matchcount> method or something like that.
> 
> I think we already said something like that once some number of
> months ago.  +$1 simply has to be the numeric value of the match.
> It's not as much of a problem as a Perl 5 programmer might think,
> since ?$1 is still true even if +$1 is 0.  Anyway, while we could have
> a method for the .matchcount, +$1[] should work fine too.  And maybe
> even +@$1, presuming that "a match object can function as an array"
> actually means "a match object knows when it's being asked to supply
> an array reference".

So the "counting" idiom in S05 becomes one of:

	$match_count += @{m:g/pattern/};
	$match_count += list m:g/pattern/;
	$match_count += m:g/pattern/.matchount;
	$match_count += (m:g/pattern/)[];		# maybe

???

-Scott
-- 
Jonathan Scott Duff
duff@pobox.com

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