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!