in reply to How do I reverse the order of the first and last word of a string?
Pretty directly,
or,my $string = 'This is my program'; print do { my @arr = split ' ', $string; join ' ', @arr[-1, 1..$#arr-1, 0],$/ };
That code uses array slices.my $string = 'This is my program'; { my @arr = split ' ',$string; print "@arr[-1, 1..$#arr-1, 0]$/" }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I reverse the order of the first and last word of a string?
by GrandFather (Saint) on Mar 11, 2007 at 06:45 UTC | |
by Zaxo (Archbishop) on Mar 11, 2007 at 06:50 UTC | |
by GrandFather (Saint) on Mar 11, 2007 at 06:57 UTC |