How swap values of two variables

PERL is magical language, I have no doubt about it. See the following simple example to swap the value of two variables

#!/usr/bin/perl -w
use strict;
use warnings;

my $a = 11;
my $b = 22;
print “a = “, $a,”b = “,$b,”\n”;

($a,$b)= ($b,$a); # here is the magic
print “a = “, $a,”b = “,$b;

No temporary variable and complex logic as compare to other languages like c#, vb and java

It is piece of cake !!! Really

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s