Re: swapping two numbers
Chris Dolan <[email protected]> Fri, 23 Jun 2006 18:55:49 -0500
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
On Jun 23, 2006, at 5:01 PM, David Westbrook wrote:
> Michael R. Wolf wrote:
>
> not in-place cause it's 3 lines, but does not use an external
> temporay value, and should be language-independent:
> x = x + y
> y = x - y
> x = x - y
> (IIRC my high school BASIC teacher taught us that)
This works:
$a -= $b = ($a += $b) - $b;
Chris
--
Chris Dolan, Software Developer, http://www.chrisdolan.net/
Public key: http://www.chrisdolan.net/public.key
vCard: http://www.chrisdolan.net/ChrisDolan.vcf