Course of Raku / Objects, I/O, and exceptions / Input and output / Working with files / Exercises / Count the characters
Solution: Count the characters
Here is a possible solution to the task.
Code
spurt 'data.txt', 'Raku';
say slurp('data.txt').chars;🦋 You can find the source code in the file count-characters.raku.
Output
4Comments
spurtwrites the stringRakuto the file.slurpreads it back as a string, and.charscounts its characters — four.If you inspect the file, you will indeed only see the four characters; the newline character is not added.