in reply to Swap the characters
The regex solutions seem to be simplest but here are a couple of alternatives. Using split, join and a slice.
$ perl -le ' $str = q{yands}; $str = join q{}, ( split m{}, $str )[ -1, 1 .. length( $str ) - 2, 0 ] +; print $str;' sandy $
Using substr.
$ perl -le ' $str = q{yands}; substr( $str, 0, 1 ) = substr $str, length( $str ) - 1, 1, substr $str +, 0, 1; print $str;' sandy $
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Swap the characters
by jwkrahn (Abbot) on Apr 14, 2009 at 13:21 UTC | |
by johngg (Canon) on Apr 14, 2009 at 13:54 UTC |