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:
> : On Fri, May 13, 2005 at 03:23:20AM +0800, Autrijus Tang wrote:
> : > Is it really intended that we get into habit of writing this?
> : > 
> : >     if 'localhost:80' ~~ /^(.+)\:(\d+)$/ {
> : >   my $socket = connect(~$0, +$1);
> : >     }
> : > 
> : > It looks... weird. :)
> : 
> : And it would have to be
> : 
> :      if 'localhost:80' ~~ /^(.+)\:(\d+)$/ {
> :     my $socket = connect(~$0, ~$1);
> :      }
> : 
> : because +$1 still evaluates to 1.  (The ~ in front of $0 is 
> : probably optional.)
> : 
> : 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.  

I guess I've been led astray (or downright confused) by the capture 
specs then, when it says:

    A successful match returns a C<Match> object whose boolean value is
    true, whose integer value is typically 1 (except under the C<:g> or
    C<:x> flags; see L<Capturing from non-singular matches>), whose string
    value is the complete substring that was matched by the entire rule,
    whose array component contains all subpattern (unnamed) captures, and
    whose hash component contains all subrule (named) captures.

and later

    If an named scalar alias is applied to a set of non-capturing 
        m:w/ $<key>:=[ (<[A-E]>) (\d**{3..6}) (X?) ] /;
    then the corresponding entry in the rule's hash is assigned a 
    C<Match> object whose:
        * Boolean value is true,
        * Integer value is 1,
        * String value is the complete substring matched by the 
          contents of the square brackets,
        * Array and hash are both empty.

and under the :g option...

     if $text ~~ m:words:globally/ (\S+:) <rocks> / {
         say "Matched {+$/} different ways";
         say 'Full match context is:';
         say $/;

So, are the Match objects returned from subpattern captures 
treated differently in numeric context than the Match objects
coming from named scalar aliases or the match itself... ?

> 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.  

With .matchcount I wasn't concerned about the number of repetitions
stored in $1 -- I was trying to get at the numeric value that $/
would've returned under the :g option.  But in re-reading the draft
of the :globally option I see we already have one --  
C< $/.matches > in numeric context should supply it for us.

So I'm guessing that we're all in agreement that +$/, +$1, and 
+$<subrule> all refer to the numeric value of the string matched, 
as opposed to what's currently written about their values in the 
draft...?  Or am I still missing the picture entirely?


Reply via email to