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

Numification of captured match

Thread Next
Autrijus Tang
May 12, 2005 12:23
Numification of captured match
Message ID:
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. :)


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