Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: reverse a string in place

by jwkrahn (Monsignor)
on Mar 24, 2013 at 22:12 UTC ( #1025189=note: print w/replies, xml ) Need Help??


in reply to reverse a string in place

$ 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025189]
help
Chatterbox?
[shmem]: unbelievable. ergo insurance germany offers a contract: paying 1.5 euro a day over 18 years, they ensure a payback of 7.501 euro
[shmem]: *if* there is a bonus due, they would pay 9.250
[shmem]: don't expect anything noteworthy from a countrie's elections in which such things are shrugged off.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-09-19 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (222 votes). Check out past polls.

    Notices?