sub swap ( $l is rw, $r is rw ) { ($r,$l) = ($l,$r) }
my $a = 1; my $b = 2; swap $a, $b; say $a; # 2;
my @a[2] = 1,2; swap |@a; say @a; # [2 1]
You can use reverse
as well as what you are trying to accomplish.
my $a = 1; my $b = 2; ($a,$b) .= reverse; say $a; # 2 say $b; # 1
source share