Getting a usable reference to an OO method

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Apologies if this turns up as a duplicate post.  I posted earlier, but it h=
asn't shown up ... making a second try.

I'm building some code that makes checksums of several files, using a confi=
gurable digest algo.  In order to avoid having to repeat the same if() bloc=
k all over the place when creating new digest objects, I'd like to do that =
once, and assign a reference to the constructor for the appropriate digest =
module at that point, which I can just re-use.  I seem to be having a hard =
time coming up with the right syntax however.

The closest I've got so far is a proof of concept that looks like this:
use Digest::MD5;

$digest = \&Digest::MD5::new;
$foo = &$digest;
$foo->add( "blahblahblah" );
print $foo->hexdigest;

This throws an error when I try to execute &$digest... I get Digest::MD5::n=
ew's usage help.  It seems it wants me to do "$foo = &$digest('Digest::MD=
5')" which doesn't really help with my original problem.  Does anyone have =
a suggestion for how to get what I want out of this?


Site Timeline