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

Numification of captured match

Thread Next
From:
Autrijus Tang
Date:
May 12, 2005 12:23
Subject:
Numification of captured match
Message ID:
20050512192320.GA46296@aut.dyndns.org
Thit has led to surprising results in Pugs's Net::IRC:

    if 'localhost:80' ~~ /^(.+)\:(\d+)$/ {
	my $socket = connect($0, $1);
    }

If $1 is a match object here, and connect() assumes Int on its second
argument, then it will connect to port 1, as the match object numifies
to 1 (indicating a successful match).

I "fixed" this for 6.2.3 by flattening $0, $1, $2 into plain scalars
(for nonquantified matches), and use $/[0] etc to store match objects,
but I'm not sure this treatment is right.

Is it really intended that we get into habit of writing this?

    if 'localhost:80' ~~ /^(.+)\:(\d+)$/ {
	my $socket = connect(~$0, +$1);
    }

It looks... weird. :)

Thanks,
/Autrijus/

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