Ryan10975073 wrote:
> 
> hi,

Hello,

> The statement ($a,$b) = ($b ,$a);  is swapping without a third variable.
> But looking at a lower level , it is storing a temporary variable in the
> registers.

Not necessarily.  :-)

$ perl -le'
my ( $x, $y ) = ( 5, 16 );
print "\$x = $x   \$y = $y";
$x ^= $y;
$y ^= $x;
$x ^= $y;
print "\$x = $x   \$y = $y";
'
$x = 5   $y = 16
$x = 16   $y = 5

$ perl -le'
my ( $x, $y ) = ( "two", "three" );
print "\$x = $x   \$y = $y";
$x ^= $y;
$y ^= $x;
$x ^= $y;
print "\$x = $x   \$y = $y";
'
$x = two   $y = three
$x = three   $y = two


> How can i get that temporary variable/value from the
> registers/memory which will have value of either $a or $b.
> Would love to see solution on that.

Just create your own temporary variable.

my $temp = $x;
$x = $y;
$y = $temp;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to