Reversing a String by Word or Character

Author: stmuk

You want to reverse words or characters in a string

Source code: 01-07reversing-strings.p6

#!/usr/bin/env perl6

use v6;

my $string = "The Magic Words are Squeamish Ossifrage";

# reverse the characters in a scalar

say $string.flip;

# reverse the words in a scalar

say $string.split(" ").reverse.join(" ");