Perl programmers bring habits with them. Some of them help in Raku, and some get in the way. These articles start from what Perl does.
False friends
- @a[-1] is not the last elementIn Python and Perl, index -1 counts from the end. In Raku it does not even compile.
- There is no length
len,.lengthandlengthdo not exist in Raku. A string has.chars, and a list has.elems. - Splitting on nothing does not give you the lettersIn JavaScript and Perl, splitting on an empty string gives the characters. In Raku you also get an empty string at each end. Use
.comb. - my $n = @array is not a countIn Perl, putting an array into a scalar variable gives you its length. In Raku, the scalar holds the whole array.
Accents
- Counting wordsThe three most frequent words in a sentence, written four times — with a Python, a Perl and a C accent, and as a native would write it.
- Totals per cityAdding up sales per city from a small table, written with a Python, a Perl and a C accent, and as a native would write it.
- Fibonacci numbers below 1000The Fibonacci numbers below 1000, written with a Python, a Perl and a C accent, and with a native Raku sequence.