📘 Doubling characters using Perl 6

In a given string, double each alphanumeric character and print the result. Punctuation and spaces should stay untouched. Regexes are very powerful tools for searching and replacing texts. In this task, only the alphanumeric characters are requested to be doubled. The \w character class is the perfect match to find these characters. my $string = ‘Hello, … Continue reading “📘 Doubling characters using Perl 6”

📘 Currency converter written in Perl 6

Parse the string with a currency converting request such as ‘10 EUR in USD’ and print the result. The task of understanding free text is quite complicated. For the currency conversion, we can create a simple regex that matches the most common quires. Let’s ignore the way the exchange rate data are obtained and use … Continue reading “📘 Currency converter written in Perl 6”

📘 Skipping Pod documentation in Perl 6

Create the program that copies the input text and skips the documentation in the Pod style that starts with =begin and ends with =end. Let us take a simple text containing a piece of Pod documentation: # Hello, World!=beginThis program prints a message=endsay ‘Hello, World!’; The program should read it and print everything that is not the … Continue reading “📘 Skipping Pod documentation in Perl 6”

📘 Count words using Perl 6

Count the number of words in a text. Before solving the task, let us assume that by words we mean here a sequence of alphanumeric characters, including the underscore symbol. Here is the solution: my $text = prompt(‘Text> ‘);say $text.comb(/\w+/).elems; Try it on a few test inputs: $perl6 countwords.pl Text> Hello, World;2 The program uses regexes … Continue reading “📘 Count words using Perl 6”

📘 Count vowels in a word using Perl 6

Count the number of vowel letters in the given word. Of course, we will abstract now from the difference between letters and sounds and will only count the number of vowel letters: a, e, i, o, and u. my $word = ‘Hello’;$word ~~ m:g:i/<[aeiou]>/;say $/.elems; Here, the given $word is matched against a regex that contains … Continue reading “📘 Count vowels in a word using Perl 6”