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

Re: Ampersands and sub speed

by friedo (Prior)
on Oct 14, 2005 at 17:15 UTC ( [id://500371]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Ampersands and sub speed

I think the reason is because calling a function with & preserves the existing @_, so perl doesn't have to mess with the argument stack. In other words, &function; is a kind-of fancy goto.

Replies are listed 'Best First'.
Re^2: Ampersands and sub speed
by diotalevi (Canon) on Oct 14, 2005 at 17:43 UTC

    No... goto() doesn't return to the next statement. This is a fancy way of saying function( @_ ).

      Closer, but they're still not the same. This code works,

      sub f { &g; print @_; } sub g { $_[0] .= "o, w"; push @_, "orld\n"; } +f($x = "hell");
      but if you change it like this, it breaks:
      sub f { g(@_); print @_; } sub g { $_[0] .= "o, w"; push @_, "orld\n"; + } f($x = "hell");

        Oh ok. That's even more evil than I would have normally thought. So &do_nothing; is like @_=do_nothing(@_) except that it doesn't make copies like would happen in that snippet.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://500371]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.