in reply to Re: What is the best solution to swap input data?
in thread What is the best solution to swap input data?

Here's a substr solution that works in situ:
my $data = '123456789'; foreach (my $i = 0; $i + 1 < length $data; $i += 2) { substr($data, $i, 2) = reverse substr($data, $i, 2); } print $data, "\n"; __END__ 214365879

Replies are listed 'Best First'.
Re^3: What is the best solution to swap input data?
by Hofmator (Curate) on Nov 09, 2006 at 15:20 UTC
    That's fenLisesi's solution here in this thread, only using an assignment instead of the 4-arg form of substr.

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.