I want to swap two variables values without using the third variable in Perl, e. g.:
my $first = 10; my $second = 20;
Please suggest me how
The Perl-specific methods already listed are best, but here's a technique using XOR that works in many languages, including Perl:
use strict; my $x = 4; my $y = 8; print "X: $x Y: $y\n"; $x ^= $y; $y ^= $x; $x ^= $y; print "X: $x Y: $y\n"; X: 4 Y: 8 X: 8 Y: 4