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/ Regards, Shlomi Fish > I need this for the "attributes" pragma. :-) > > TIA! > Eric > > -- > Eric MSP Veith <eric.ve...@de.ibm.com> > Hechtsheimer Str. 2 > DE-55131 Mainz > Germany > > IBM Deutschland GmbH > Vorsitzender des Aufsichtsrats: Erich Clementi > Geschäftsführung: Martin Jetter (Vorsitzender), Reinhard Reschke, > Christoph Grandpierre, Matthias Hartmann, Michael Diemer, Martina > Koederitz > Sitz der Gesellschaft: Stuttgart > Registergericht: Amtsgericht Stuttgart, HRB 14562 > WEEE-Reg.-Nr. DE 99369940 -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ "Humanity" - Parody of Modern Life - http://shlom.in/humanity Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/