Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is rindex broken or does my brain need a reboot?

18 views
Skip to first unread message

Frederik Schwarzer

unread,
May 7, 2012, 11:19:40 PM5/7/12
to perl6...@perl.org
Hi,

I had a little problem with rindex and wrote a small demo code that
shows what I found.

The code is:
use v6;

my $string = "perl";
say $string;
say $string.WHAT;
say $string.index("e");
say $string.rindex("e");

say "";
say @*ARGS[0];
say @*ARGS[0].WHAT;
say @*ARGS[0].index("e");
say @*ARGS[0].rindex("e");

When run, I see the following (with a two-week old build of Rakudo
master):
$ perl6 index.pl perl
perl
Str()
1
1

perl
Str()
1
Failure.new(exception => X::AdHoc.new(payload => "substring not
found"))

Do I miss something? Any help is appreciated.

Regards

Stefan O'Rear

unread,
May 8, 2012, 4:02:24 AM5/8/12
to perl6...@perl.org
$ install/bin/perl6 -e 'say nqp::p6box_s(pir::encodingname__SI(pir::encoding__IS(@*ARGS[0])))' perl
utf8

$ install/bin/perl6 -e 'say nqp::p6box_s(pir::encodingname__SI(pir::encoding__IS("perl")))' perl
ascii

$ install/bin/perl6 -e 'say "perł".rindex("e");' perl
substring not found
in method gist at src/gen/CORE.setting:8140
in sub say at src/gen/CORE.setting:6244
in block <anon> at -e:1

$ install/bin/perl6 -v
This is perl6 version 2012.03-27-g5793035 built on parrot 4.2.0 revision RELEASE_4_2_0


rindex appears to not like utf-8 encoded strings very much.

-Stefan
signature.asc

Patrick R. Michaud

unread,
May 8, 2012, 9:28:12 AM5/8/12
to Stefan O'Rear, perl6...@perl.org
On Tue, May 08, 2012 at 01:02:24AM -0700, Stefan O'Rear wrote:
> On Tue, May 08, 2012 at 05:19:40AM +0200, Frederik Schwarzer wrote:
> > Hi,
> >
> > I had a little problem with rindex and wrote a small demo code that
> > shows what I found.
> $ install/bin/perl6 -e 'say "perł".rindex("e");' perl
> substring not found
> in method gist at src/gen/CORE.setting:8140
> in sub say at src/gen/CORE.setting:6244
> in block <anon> at -e:1
>
> $ install/bin/perl6 -v
> This is perl6 version 2012.03-27-g5793035 built on parrot 4.2.0 revision RELEASE_4_2_0
>
>
> rindex appears to not like utf-8 encoded strings very much.

Good catch! Now reported as Parrot issue #767 and RT #112818.

Pm

Frederik Schwarzer

unread,
May 8, 2012, 2:16:49 PM5/8/12
to perl6...@perl.org
Thanks Stefan for explaining the issue and Patick for taking the
appropriate steps. :)

Regards

Moritz Lenz

unread,
May 10, 2012, 3:40:44 AM5/10/12
to perl6...@perl.org
Now fixed in 2012.04.1-93-g128e996:

$ ./perl6 -e 'say @*ARGS[0].rindex("e")' perl
1
0 new messages