Referencing Perl

This blog is created to share perl resources all round the world and to explore the same.

Name:
Location: Chennai, TamilNadu, India

A Computer Freak, interested in programming open source

Wednesday, March 30, 2005

Swapping of two number without any temporary variables

$a =1;
$b =2;
$b ^= $a ^= $b ^= $a;
print "a = $a, b = $b\n";
--prasanna.k

3 Comments:

Anonymous Anonymous said...

My eyes are bleeding.

7:39 PM  
Anonymous Pandiaraj said...

Hey dude,

See the simple way of doing this,

$a = 1;
$b = 2;
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
print "a=$a, b=$b\n";

4:55 AM  
Anonymous Senthilkumar said...

Dont Look for Complex solution for a simple problem :-)
$a = 10;
$b = 20;
($a,$b) = ($b,$a);
print "a=$a, b=$b\n";

7:59 PM  

Post a Comment

<< Home