Skip to content

Commit

Permalink
more LHF examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stmuk committed Apr 20, 2015
1 parent 43d78b6 commit d9c1e3e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions categories/cookbook/01strings/01-06reversing-strings.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use v6;

=begin pod
=TITLE Reversing a String by Word or Character
=AUTHOR stmuk
You want to reverse words or characters in a string
=end pod

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;

# vim: expandtab shiftwidth=4 ft=perl6
20 changes: 20 additions & 0 deletions categories/cookbook/01strings/01-19-trim-whitespace.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use v6;

=begin pod
=TITLE Trimming whitespace from both ends of a string
=AUTHOR stmuk
You have a string with leading and/or trailing whitespace
you wish to remove
=end pod

my $string = "\t the cat sat on the mat ";

$string.=trim;

say :$string.perl;

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit d9c1e3e

Please sign in to comment.