Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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


Comment on Re: reverse a string in place
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-08-21 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (139 votes), past polls