Skip to content

Commit d9c1e3e

Browse files
committed
more LHF examples
1 parent 43d78b6 commit d9c1e3e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Reversing a String by Word or Character
6+
7+
=AUTHOR stmuk
8+
9+
You want to reverse words or characters in a string
10+
11+
=end pod
12+
13+
my $string = "The Magic Words are Squeamish Ossifrage";
14+
15+
# reverse the characters in a scalar
16+
17+
say $string.flip;
18+
19+
# reverse the words in a scalar
20+
21+
say $string.split(" ").reverse;
22+
23+
# vim: expandtab shiftwidth=4 ft=perl6
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Trimming whitespace from both ends of a string
6+
7+
=AUTHOR stmuk
8+
9+
You have a string with leading and/or trailing whitespace
10+
you wish to remove
11+
12+
=end pod
13+
14+
my $string = "\t the cat sat on the mat ";
15+
16+
$string.=trim;
17+
18+
say :$string.perl;
19+
20+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)