in reply to Re^2: passing subroutine references
in thread passing subroutine references

but is it really that expensive to do in my original code? aren't we just passing an address to the code, not the code itself?

Replies are listed 'Best First'.
Re^4: passing subroutine references
by ikegami (Patriarch) on Sep 20, 2009 at 17:27 UTC

    Honestly, I don't know how big a waste of memory it is. When it comes to recursive functions, having a big state can be a problem. It's a good idea to avoid a large state unless you can show it's not a problem rather than the other way around. Factoring out unchanging variables is an easy and low-cost way of reducing the size of the state.

    It would be a bigger problem in another language where the stack has a limited size. Perl dynamically allocates each stack frame on the heap, so it's not limited like in C.

Re^4: passing subroutine references
by Jenda (Abbot) on Sep 20, 2009 at 21:42 UTC

    No it's not. We are of course passing just the reference.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.