On 2010.04.07 16:39, Shlomi Fish wrote: > On Wednesday 07 Apr 2010 19:23:25 Eric Veith1 wrote: >> Hello Perlers, >> >> this is probably going to be quick one. I know how to get an subroutine >> reference under "normal" circumstances, but I don't know how to get one >> from an object instance. Like: >> >> ---%<--- >> my $foo = My::Foo->new("bleh"); >> >> # Calling the sub: >> $foo->quux; >> >> # How would I get the reference to the sub just called, so that I could >> do: >> $quuxref->(); >> --->%--- >> > > You can do something like: > > [perl] > my $quuxref = sub { return $foo->quux; }; > . > . > . > $quuxref->(); > [/perl] > > I.e: by using a closure which has some state. Also see: > > http://www.shadowcat.co.uk/blog/matt-s-trout/madness-with-methods/
At a quick glance, that is going to be a very nice read. I can already tell it will solve at least one bug that I still have active and not yet been able to fix in one of my larger applications. Thanks Shlomi, and everyone else who continuously enhances their posts with links to relevant information, and/or the relevant perldoc references. Cheers! Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/