Course of Raku / Addendum 🆕 / Working with data / Text and strings / Exercises / Count the vowels

Solution: Count the vowels

Here is a possible solution to the task.

Code

my $text = 'Programming in Raku';

say +$text.comb(/ <[aeiouAEIOU]> /);

🦋 You can find the source code in the file count-vowels.raku.

Output

6

Comments

  1. Passing a regex to .comb returns every matching character. The character class <[aeiouAEIOU]> lists the vowels in both cases.

  2. The prefix + puts the resulting list into numeric context, giving its length — the number of vowels.

Course navigation

Count the vowels   |   Title case