Course of Raku / Advanced / Operators / Meta-operators / Exercises / Build a URL
Solution: Build a URL
Here is a possible solution to the task.
Code
my @parts = <http :// example .com>;
my $url = [~] @parts;
say $url;
say $url.chars;🦋 You can find the source code in the file concatenate-a-list.raku.
Output
http://example.com
18Comments
The array is written with the angle-bracket quoting form
<...>, which is the same as'http', '://', 'example', '.com'.The reduction meta-operator
[~]places the string-concatenation operator~between all the elements, so[~] @partsglues the four pieces into the single stringhttp://example.com.Storing the result in
$urllets us reuse it:$url.charsthen reports that the assembled URL is18characters long.