develooper Front page | perl.perl5.porters | Postings from July 2009

Re: [PATCH] Remove implicit split to @_

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
July 10, 2009 08:29
Subject:
Re: [PATCH] Remove implicit split to @_
Message ID:
20090710152934.GA24401@klangraum.plasmasturm.org
* John W. Krahn <jwkrahn@shaw.ca> [2009-07-10 13:10]:
> Aristotle Pagaltzis wrote:
> > OTOH `1 + $str =~ m//g` works in the general case and is far
> > less unintuitive.
>
> `1 + $str =~ m//g` doesn't work at all. The match operator is
> empty so it will use the regular expression from the last
> successfull match, which will probably not match just
> whitespace, or else it will match between every character.

Yeah, and I didn’t declare `$str`, nor did I save the result of
the expression anywhere. Or maybe it wasn’t supposed to be a
copy-paste ready usage example, but merely the essence of the
expression.

> But more importantly, because the match operator is used in an
> arithmetic expression it is in scalar context and so will
> return either true or false (1 or 0 in numerical context) and
> not the number of matches.

This, in contrast, is a good point. What I was thinking of is
not `m//g` but `s///g`, which does all substitutions at once and
returns a count. Of course that’s only useful if you don’t care
about conserving the string’s contents.

For `m//g` to work it needs to be `1 + ( () = $str =~ m//g )`,
which is a lot worse than the `y///` incantation.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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