in reply to swapping vars, two ways, 2 results...
you are not swaping, you simply defined another set of variables. Try this, it will clearly show you what happend, and why it is way fast:my ($b, $a) = ($a, $b)
Update:$a = 100; $b = 200; my ($a, $b) = ($b, $a); print $a, "\n"; #200 print $b, "\n"; #100 print $main::a, "\n";#100 print $main::b, "\n";#200
You are not working against two scalars, in stead you are working against two arrays, and two scalars. Not that it is slow, I don't even think it take less memory as you thought. Although you are not using any temps, Perl is using.($b, $a) = ($a, $b)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: swapping vars, two ways, 2 results...
by Sihal (Pilgrim) on Dec 18, 2002 at 23:04 UTC | |
|
Re: Re: swapping vars, two ways, 2 results...
by Sihal (Pilgrim) on Dec 18, 2002 at 22:51 UTC | |
by BrowserUk (Patriarch) on Dec 18, 2002 at 23:08 UTC |