in reply to closure question

Is there any reason you need the subroutine to be separate for each element? Let perl compile it once and use the same coderef for each element if you can, as that saves on memory and work. That doesn't prevent you from overriding those definitions with another coderef if you need to.

Also, don't be confused by the "DUMMY" bit (not that you've given any indication that you are confused -- mainly this is for the benefit of others). Data::Dumper can't deal with coderefs, so it just inserts a subroutine that is effectively a no-op, and returning "DUMMY" is as good as anything else.

Replies are listed 'Best First'.
Re: Re: closure question
by nop (Hermit) on Feb 02, 2001 at 02:23 UTC
    Good point. I was getting confused by the Dumper representation: I was worried that if I changed the 'a' coderef, then 'b' and 'c' would point to garbage. (Repeat often: Perl isn't C! Perl Isn't C! Perl isn't C! Hurrah.) The way I understand reference counting, the anon sub will stay around until the last reference to it goes away. The way Dumper printed it, I was incorrectly thinking that the 'a' coderef was somehow "primary", and the 'b' and 'c' refs were somehow subordinate.

    As for writing subroutines that don't seem to do much... hey, that's my login name, nop!