Re: swapping two numbers

David Westbrook <[email protected]> Fri, 23 Jun 2006 18:01:55 -0400
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Michael R. Wolf wrote:

>I was digging through some old code and came across a proof that I had done
>that you can swap two numbers in place (i.e. without using an external
>temporary value).
>
>Of course, in Perl, we can just do this:
> ($x, $y) = ($y, $x)
>  
>
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)