Splitting on nothing does not give you the letters

In JavaScript and Perl, splitting on an empty string gives the characters. In Raku you also get an empty string at each end. Use .comb.

To get the letters of a word, JavaScript and Perl programmers split it on nothing. In Raku that gives you two extra pieces.

In JavaScript

console.log("Riga".split(""));
[ 'R', 'i', 'g', 'a' ]

In Perl

my @letters = split //, "Riga";
print join(" ", @letters), "\n";
print scalar(@letters), "\n";
R i g a
4

In Python

Python refuses an empty separator and has list instead:

try:
    print("Riga".split(""))
except ValueError as e:
    print("ValueError:", e)
print(list("Riga"))
ValueError: empty separator
['R', 'i', 'g', 'a']

In Raku

say "Riga".split("");
say "Riga".split("").elems;
( R i g a )
6

Look at the spaces inside the parentheses. Before R and after a there is an empty string, so the list has six elements, not four.

Why

.split cuts the string at every place where the separator is found, and keeps everything between the cuts, even when it is empty. An empty separator is found everywhere: between the letters, but also before the first letter and after the last one. That makes five cuts in a four-letter word, and six pieces.

JavaScript and Perl treat the empty separator as a special case and drop the empty pieces at the ends. Raku does not make a special case.

Say it in Raku

.comb without an argument gives you the characters:

say "Riga".comb;
say "Riga".comb.elems;
(R i g a)
4

When you do split and want no empty pieces, say so with :skip-empty:

say "Riga".split("", :skip-empty);
(R i g a)