home

Quickies, by Andrea Olivato

text

How to switch 2 $vars value in #Perl

How to simply switch two variables values in Perl.

#!/usr/bin/perl

# Assigning 2 vars
my $some = "some";
my $thing = "thing";

# Switching them
($some, $thing) = ($thing, $some);

# See what happened
print '$some is now "'.$some.'"';
print "\n";
print '$thing is now "'.$thing.'"';

2 years ago

May 25, 2009
Comments (View)
blog comments powered by Disqus