Getting a usable reference to an OO method

M

Matthew Pounsett

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

I'm building some code that makes checksums of several files, using a configurable digest algo. In order to avoid having to repeat the same if() block 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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top