Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Query anout module loading

by firearm12 (Novice)
on Apr 28, 2012 at 07:43 UTC ( #967776=perlquestion: print w/ replies, xml ) Need Help??
firearm12 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys, I have got a situation where I want to use Digest::MD5 module for calculating checksums, but not all of the machines in my environemnt have this module especially older perl verisons. So, I decided to go with the solution to load this module only if its installed on the machine otherwise use '/usr/bin/cksum' to calculate the checksum. I used something like below to achieve this:
if (eval {require Digest::MD5}) { my $flcn=Digest::MD5->new(); .. .. } else { my cksum=`/usr/bin/cksum $file`; . .. }
This seems to work fine. Now, my question is this that is this right to use this kind of invocation. Can I get problems in some other perl versions if I use this? What kind of effects does this have on the program? Is there some better way to load a particular module only if its installed on a machine?

Comment on Query anout module loading
Download Code
Re: Query anout module loading
by Anonymous Monk on Apr 28, 2012 at 08:25 UTC

    Now, my question is this that is this right to use this kind of invocation

    Yes, this is the correct invocation

    Can I get problems in some other perl versions if I use this?

    Not with anything perl 5.* , you shouldn't worry about older perl's

    What kind of effects does this have on the program?

    Nothing besides duplicating work and all the pitfalls associated with that. If you can't install modules, you should consider distributing a perl, ie PAR/pp/http://www.cava.co.uk//PerlApp

    Is there some better way to load a particular module only if its installed on a machine?

    Not really, all the different helpers ( if, Module::Pluggable, Module::Load ... ) eventually call require

      Thanks very much
Re: Query anout module loading
by graff (Chancellor) on Apr 28, 2012 at 18:41 UTC
    The plan looks okay to me too, except I wonder why you aren't using the "md5" (or "md5sum") command instead of "cksum". Is comparability of output across systems not an issue in your case?

    (If you wanted to know whether files on two different systems had identical content, you'd want the md5 sum from both files; having cksum output from one and md5 output from the other isn't informative in any way.)

      No, actually md5sum command is not available on all the hosts, so I cant use that. I am comparing a file's checksum against a previously stored list (that contains both md5sum and cksum of the file). So, using md5sum for those servers that have it and cksum for those who dont have md5.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://967776]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-07-28 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls