use strict; use warnings; use Data::Dump; my $x = 1; my $y = 2; print "x = $x, y = $y\n"; swap($x, $y); print "x = $x, y = $y\n"; sub swap # External SWAP? { # -------------- # @_ = reverse @_; # NO # ( $_[0], $_[1] ) = ( $_[1], $_[0] ); # YES # @_[0, 1] = @_[1, 0]; # YES - slice # splice @_, 0, 2, reverse @_; # NO - splice # splice @_, 0, 2, ( $_[1], $_[0] ); # NO - splice # @_[$#_ + 1] = 12; # Preserves aliasing # push @_, 'x'; # Preserves aliasing unshift @_, 'y'; # Preserves aliasing, but changes indices $_[1] = 55; dd \@_; }