$ perl -le' my $string = "abcdefghi"; print $string; # get the address of every character my @addr = map \substr( $string, $_, 1 ), 0 .. length( $string ) - 1; # swap the characters in-place. ( ${$addr[ $_ ]}, ${$addr[ -( $_ + 1 ) ]} ) = ( ${$addr[ -( $_ + 1 ) ] +}, ${$addr[ $_ ]} ) for 0 .. $#addr / 2; print $string; ' abcdefghi ihgfedcba
In reply to Re: reverse a string in place
by jwkrahn
in thread reverse a string in place
by Priti24
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |