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

Re: Numification of captured match

Thread Previous | Thread Next
Patrick R. Michaud
May 12, 2005 12:55
Re: Numification of captured match
Message ID:
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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About