Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I find where these modules are located on my Solaris 7 web server:
use LWP::Simple; use Mail::Sendmail;
We have Perl 5.8

Replies are listed 'Best First'.
Re: Finding modules
by borisz (Canon) on Jan 27, 2004 at 17:31 UTC
    perl -le 'use LWP::Simple; use Mail::Sendmail; for ( keys %INC ) { pri +nt $INC{$_} if m!/(Simple|Sendmail)!}'
    Boris
Re: Finding modules
by broquaint (Abbot) on Jan 27, 2004 at 17:35 UTC
    Just use the modules and then look at their inclusion path in %INC e.g
    perl -MLWP::Simple -MMail::Sendmail -le \ 'print "$_: $INC{$_}" for qw( LWP/Simple.pm Mail/Sendmail.pm )'
    You might also want to look at your local perllocal via perldoc perllocal.
    HTH

    _________
    broquaint

      I found this:
      /usr/local/lib/perl5/5.8.0/Filter/Simple.pm /usr/local/lib/perl5/5.8.0/Test/Simple.pm
      Now how do I get the LWP::Simple to work from here?
      #!/usr/local/bin/perl use lib '/usr/local/lib/perl5/5.8.0/Test/'; use LWP::Simple;
      Is the above correct? Does Simple.pm store LWP::Simple??
        No, it means you have the modules Filter::Simple and Test::Simple installed. No LWP::Simple at all. try installing it first with perl -MCPAN -e'install LWP::Simple'for example.
        Boris
Re: Finding modules
by b10m (Vicar) on Jan 27, 2004 at 17:34 UTC

    If you have no clue where you (or `cpan`) installed your files, you can use `find` (see `man find` for more):

    $ find /usr/ -name Simple.pm [...] $ find /usr/ -name Sendmail.pm [...]

    Most likely, it's installed somewhere in /usr/. If nothing returns, you might try:

    $ find / -name Simple.pm

    I'm not sure wheter Solaris has the `locate` app. Otherwise that'd be even faster:

    $ locate Simple.pm

    HTH

    Update: but of course, borisz' answer is way nicer :)

    --
    b10m

      Of course there is no guarantee that your modules are installed in /usr/ so you may want to find the directories you are searching using the following code if you are using b10m's solution:

      use strict; use warnings; foreach my $path (@INC) { print "There are modules in: $path\n"; }

      Note that you need read access to these directories, so if your box is properly locked down this may mean you need root access.

        Of course there is no guarantee that your modules are installed in /usr/ so you may want to find the directories you are searching using the following code if you are using b10m's solution

        Of course there's no guarantee, that's why I wrote "most likely". "My solution" comes in handy when you know you installed the modules, but you somehow can't seem to use them (read: they're not in %INC). Otherwise, I would strongly suggest to use for example borisz' solution.

        Note that you need read access to these directories, so if your box is properly locked down this may mean you need root access.

        You would have quite a paranoid sysadmin, if you can't read the Perl modules' directories, but of course, it's possible :)

        --
        b10m
      A slight modification on this so you don't get error messages would be to do:
      $ find / -name Simple.pm 2>/dev/null $ find / -name Sendmail.pm 2>/dev/null

      And I'm certain it could be done in one line with a regexp :-)


      "Ex Libris un Peut de Tout"
        And I'm certain it could be done in one line with a regexp :-)

        You asked for it! ;)

        find / -regex '.*S\(imple\|endmail\)\.pm$' 2>/dev/null
        --
        b10m

        All code is usually tested, but rarely trusted.
Re: Finding modules
by antirice (Priest) on Jan 27, 2004 at 18:45 UTC

    I have a script for this that I use all the time. Just put it in a reachable path and make it executable.

    #!/usr/bin/perl -l for (@ARGV) { (my $a.="$_.pm") =~s#::#/#g; eval { require $a; }; print "$_: ",$@?"Not found":$INC{$a}; }

    Then you just call it with:

    findmod LWP::Simple Mail::Sendmail

    While I'm on the subject, I also find this script to be really helpful:

    #!/usr/bin/perl -l $_=shift; ($_.=".pm")=~s#::#/#g; eval { require $_ }; exec("vi",$INC{$_}) unless $@; print "Module not found"

    And I call it as:

    editmod LWP::Simple

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

Re: Finding modules
by Caron (Friar) on Jan 27, 2004 at 21:48 UTC

    See whichpm and the related discussion for a general purpose method of finding modules.

Re: Finding modules
by YuckFoo (Abbot) on Jan 27, 2004 at 18:49 UTC
    perldoc -l LWP::Simple

    YuckFoo

      That will only find the POD. If POD and pm are in two different files, then you are out of luck.

      See Re: Re: whichpm for more comments.

        Thanks, I didn't know that. But then there is always perldoc -m LWP::Simple

        YuckFoo

        Yes, but that is far simpler than any of the other answers mentioned, and works for most modules - the modules with separate pod files aren't as common, and the pod file is usually in the same repository (same general path) as the pm file itself, so it's still pointing you in the right direction.

        Personally, I prefer the quick and concise method that works most of the time. If it fails, then I'd go after one of the more complex methods listed here.

        ++ to the OP. If he hadn't posted it, I would have.

        ~J

Re: Finding modules
by JSchmitz (Canon) on Jan 29, 2004 at 04:53 UTC
    you can also fire up the CPAN prompt like so: perl -MCPAN -e shell and type "autobundle" and it will generate a list of all the modules installed and output them to a file for you. It shows you the path to the file at the end. I think the list has the install path of the mods also. Cheers!!

    Jeffery