Grokbase
Topics Posts Groups | in
x
[ help ]

Re: Smartmatch with regex in list context

View PostFlat  Thread  Threaded | < Prev - Next >
A. Pagaltzis Re: Smartmatch with regex in list context
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
* Moritz Lenz <moritz@casella.verplant.org> [2008-09-01 13:10]:
> $ perl -wMstrict -E "say scalar (my @a = 'aaa' =~ /./g)"
> 3
> $ perl -wMstrict -E "say scalar (my @a = 'aaa' ~~ /./g)"
> 1
>
> (from http://www.perlmonks.org/?node_id=708150 ), both with
> perl 5.10.0 and blead.
>
> Is this intentional? If yes, we should add s small warning to
> perlsyn. I'd prefer to have =~ and ~~ behave the same in list
> context.

But then ~~ against a string in list context would be different
from ~~ against a regex in list context. Is it more important
for ~~ to be consistent with =~ or more important for it to be
consistent with itself? (This is not a rhetorical question. I
suppose the answer is “itself,” but I have not thought of any
solid argument other than that self-consistency for the sake
of self-consistency is an obvious-seeming right choice.)

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

Thread : Smartmatch with regex in list context
1)
Moritz Lenz Hi, $ perl -wMstrict -E "say scalar (my @a = 'aaa' =~ /./g)" $ perl -wMstrict -E "say scalar (my @a...
2)
A. Pagaltzis But then ~~ against a string in list context would be different from ~~ against a regex in list...
3)
Moritz Lenz I can't answer that question; I only know that in Perl 6, (which inspired ~~ in the first place)...
spacer
View PostFlat  Thread  Threaded | < Prev - Next >