Since we can assign into an array slice, it can be shortened down to something like:
@$array[$i,$i+1] = @$array[$i+1,$i];
See it in action below....
#!/usr/bin/perl -wT
use strict;
my $arrayref = ['A','B','C','D'];
print "Before: ", join(' ',@$arrayref), "\n";
@$arrayref[1,2] = @$arrayref[2,1]; # assign into an array slic
+e
print "After : ", join(' ',@$arrayref), "\n";
=output
Before: A B C D
After : A C B D
-Blake
|