SPOILER Re: SPUG: scalar swap challenge

Colin Meyer cmeyer at helvella.org
Thu Oct 9 12:43:33 CDT 2003


Here's a Perlish solution. Because of Perl's automatic coercion of data
types, it works with strings, integers or floats. It won't work with
references, but it would *appear* to work for objects with
stringification overloaded. ;-)

#!/usr/bin/perl
$a = 'one';
$b = 'two';
                                                                                
print "$a  $b\n";
                                                                                
$a .= $b;
$b = substr $a, 0, length($a) - length($b);
$a = substr $a, length($b), length($a);
                                                                                
print "$a  $b\n";

__END__

Have fun,
-Colin.



More information about the spug-list mailing list