Carl Mäsak wrote:
> Yesterday I got bitten by the fact that currently in Rakudo, $/
> doesn't copy content from the matched string, but instead trusts that
> it stays in the matched string and doesn't change.
> 
> Is this the intended behaviour, or should $/ keep a copy the string
> contents? As the following examples show, Im hoping for the latter.
> 
>  # should $/ really keep ties to $s like this?
> <masak> rakudo: my $s = "hello"; $s ~~ /hello/; $s = "goodbye"; say $/
> <p6eval> rakudo 29834: OUTPUT[goodb␤]

I'm pretty sure it's a bug in rakudo.
The "live tie" you mentioned in the subject should only be present if
the :rw modifier is given (but even then I think it should only work the
other way round).


>  # I mean, it's not only unintuitive, it's dangerous, too
> <masak> rakudo: my $s = "abcdefg"; $s ~~ /efg/; $s = "abc"; say $/
> <p6eval> rakudo 29834: OUTPUT[Cannot take substr outside
> string␤current instr.: 'parrot;PGE::Match;text' pc 328
> (compilers/pge/PGE/Match.pir:220)␤]
> 
> # this is how I discovered this behaviour. action at a distance!
> <masak> rakudo: my $t = 'ABC'; $t ~~ /(A)B(C)/; $t = $0; my $u = $1;
> <p6eval> rakudo 29834: OUTPUT[Cannot take substr outside
> string␤current instr.: 'parrot;PGE::Match;text' pc 328
> (compilers/pge/PGE/Match.pir:220)␤]
> 
> # the fact that there's such a method as .orig gives me some hope that
> # the above is not the intended behaviour. however, as you see, $/.orig
> # is not implemented in rakudo.
> <masak> rakudo: my $s = "hello"; $s ~~ /ello/; say $/.orig
> <p6eval> rakudo 29834: OUTPUT[Method 'orig' not found for invocant of
> class  'PGE::Match'␤current instr.: '_block11' pc 60 (EVAL_14:24)␤]
> 
> S05:2377:
> 
> The currently defined methods are
> 
>     $/.from   # the initial match position
>     $/.to     # the final match position
>     $/.chars  # $/.to - $/.from
>     $/.orig   # the original match string
>     $/.text   # substr($/.orig, $/.from, $/.chars)

$/.text seems to be a bit superfluous, because it's already available as
~$/ and $/.Str

But that only as a side note.

Cheers,
Moritz

-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/

Reply via email to