Perl swap two variables

This is a easy way to swap 2 ore more variables in a short and easy way in Perl.In this solution you don’t need a third variable as store.

my $a=37;
my $b=55;
print "a:$a b:$b n";
($a,$b) = ($b,$a);
print "a:$a b:$b n";

And as result we get this:

a:37 b:55 
a:55 b:37

One thought on “Perl swap two variables”

  1. continuously i used to read smaller posts that also clear their motive, and that is certainly
    also happening using this post that i am reading now.

Leave a Reply

Your email address will not be published.

1 × two =