Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: swapping vars, two ways, 2 results...

by Sihal (Pilgrim)
on Dec 18, 2002 at 22:51 UTC ( [id://220973]=note: print w/replies, xml ) Need Help??


in reply to Re: swapping vars, two ways, 2 results...
in thread swapping vars, two ways, 2 results...

but why is it that much faster ?
  • Comment on Re: Re: swapping vars, two ways, 2 results...

Replies are listed 'Best First'.
Re: Re: Re: swapping vars, two ways, 2 results...
by BrowserUk (Patriarch) on Dec 18, 2002 at 23:08 UTC

    This ($a,$b) = ($b,$a); is notionally equivalent to

    { local @list; $list[0]=$b; $list[1]=$a; $a=$list[0]; $b=$list[1]; undef @list; }

    Instead of allocating one temprary scalar and doing 3 assignments, it is allocating a temporary list, performing 4 assignments and deallocating the list.


    Examine what is said, not who speaks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://220973]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-26 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found