Getting a usable reference to an OO method

Discussion in 'Perl Misc' started by Matthew Pounsett, Jul 27, 2011.

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

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

    Thanks!
     
    Matthew Pounsett, Jul 27, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RedEye
    Replies:
    0
    Views:
    738
    RedEye
    Sep 1, 2005
  2. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    IIS on XP Pro is now so slow it's not usable.

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Sep 22, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    2,211
    S. Justin Gengo
    Sep 22, 2005
  3. Arthur Connor
    Replies:
    9
    Views:
    628
  4. Michael Perle
    Replies:
    4
    Views:
    135
    Michael Perle
    May 23, 2006
  5. Michael Perle
    Replies:
    0
    Views:
    146
    Michael Perle
    May 19, 2006
Loading...

Share This Page