$method = $object->method;
which wasn't doing anything close to what I needed. I soon realized that I didn't need the output but the actual subroutine reference.. so I came up with:
$method = \&{$object->method};
At that time, it was about 1 AM (and I had spend the better part of the evening watching TV while not trying to think about code in an effort to come to an aha-erlebnis. Something like
$method = \&Object::method;
might be a better idea, as long as I don't forget to pass the $object as the first argument.
Todays lesson: Never work on code while watching Kate Beckinsale jump around in weird outfits. Never post a blog entry about coding while watching Kate Beckinsale in weird outfits before drinking coffee.
Coderefs? (Score:2)
-Dom
Re: (Score:1)
Re: (Score:2)
-Dom
The proper way (Score:1)
Hardcoding considered suboptimal (for a range of reasons). You want this:
You have to remember to pass a reference to
$objectin either case, though. No getting around that in Perl.Therefore you would normally use a closure as per Dominic’s suggestion.