Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: Testing for a module's presence

by Anonymous Monk
on Feb 06, 2005 at 05:54 UTC ( [id://428442]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Testing for a module's presence
in thread Testing for a module's presence

If memory is an issue, traversing @INC may be your best option.

So if I used File-Find to traverse @INC, looking for Some::Module, that would be faster and more efficient that using a require within an eval? I keep thinking that if I have over 1,000 modules on my system, I will be doing a lot time-consuming searching. Am I wrong to look at it this way?

Replies are listed 'Best First'.
Re^6: Testing for a module's presence
by Tanktalus (Canon) on Feb 06, 2005 at 05:58 UTC

    Thank you for explaining the algorithm you were thinking of. It's a bit off ;-)

    use File::Spec; my $mod_path; foreach my $i (@INC) { if ( -f File::Spec->catfile($i, 'Some/Module.pm') ) { $mod_path = $i; last; } } if ($mod_path) { # Some::Module is installed here. } else { # Some::Module is not installed anywhere. }

    The number of tests is directly proportional to the number of paths in @INC (that is, O(scalar @INC)), and is completely independant of the number of other modules that may be installed in any include path.

      Thanks... I will try that code out in the morning! Wait, wait, real programmers don't wait until the morning!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428442]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found