Using a regex is a little more compact:
use strict; use warnings; my $str = '12345678'; $str =~ s/(.)(.)/$2$1/g; print $str;
Prints:
21436587
Update: BTW, using $a and $b as variables is a bad idea. They are the variables used by sort.
In reply to Re: What is the best solution to swap input data?
by GrandFather
in thread What is the best solution to swap input data?
by bh_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |