SPOILER Re: SPUG: scalar swap challenge

Colin Meyer cmeyer at helvella.org
Fri Oct 10 02:34:09 CDT 2003


On Thu, Oct 09, 2003 at 07:34:22PM -0700, David Dyck wrote:
> On Thu, 9 Oct 2003 at 10:43 -0700, Colin Meyer <cmeyer at helvella.org> wrote:
> 
> > $a .= $b;
> > $b = substr $a, 0, length($a) - length($b);
> > $a = substr $a, length($b), length($a);
> 
> Good, but how about using the replacement argument to substr.
> 
> #!/usr/bin/perl
> $a = 'one';
> $b = 'two';
> 
> print "$a  $b\n";
> $b = substr($a, 0, length $a, $b);
> print "$a  $b\n";
> 

Very nice.

-Colin.



More information about the spug-list mailing list