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;
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;