Re: swapping two numbers
[email protected] (David Westbrook)
| Newsgroups | perl.fwp |
|---|---|
| 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)