in reply to Re: Swap the characters
in thread Swap the characters

$ perl -le ' $str = q{yands}; ( substr( $str, 0, 1 ), substr $str, -1 ) = ( substr( $str, -1 ), subs +tr $str, 0, 1 ); print $str; ' sandy

Replies are listed 'Best First'.
Re^3: Swap the characters
by johngg (Canon) on Apr 14, 2009 at 13:54 UTC

    I don't know how I came to forget about using a negative offset with substr. Thanks for pointing it out.

    $ perl -le ' $str = q{yands}; substr( $str, 0, 1 ) = substr $str, -1, 1, substr $str, 0, 1; print $str;' sandy $

    Cheers,

    JohnGG