Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Perl One Liner to Check Location of a Module

by Anonymous Monk
on Apr 09, 2007 at 13:38 UTC ( [id://608961]=perlquestion: print w/replies, xml ) Need Help??

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

Suppose I want to check where is the module Foo::Bar was stored. How can we do that with a one-liner?
  • Comment on Perl One Liner to Check Location of a Module

Replies are listed 'Best First'.
Re: Perl One Liner to Check Location of a Module
by xdg (Monsignor) on Apr 09, 2007 at 13:48 UTC
    $ perldoc -l Foo::Bar

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Yes. We use this in a shell function defined in .bashrc:
      viperl() { vi `perldoc -l $1 | sed -e 's/pod$/pm/'` }
      which begins a vi session on the module in question so you can see if it has the code you thought it did.

      Phil

      If the module has both a .pod and a .pm, an undocumented trick is to say: perldoc -lm Foo::Bar and you get the .pm and not the .pod.

        I don't think it needs the -l in that case.

        perldoc -m Foo::Bar

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Perl One Liner to Check Location of a Module
by shmem (Chancellor) on Apr 09, 2007 at 14:25 UTC
    TIMTOWTDI :-)
    perl -le 'use Foo::Bar; print $INC{"Foo/Bar.pm"}'

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

      I keep the following shell script around:

      #!/bin/sh perl "-M$1" -e 'print map { sprintf( "%20s : %s\n", $_, $INC{$_} ) } s +ort keys %INC; print "\n'$1' version : $'$1'::VERSION\n\n"'
      TIMTOWTDI :-)

      Yep, and some of them were mentioned previously. (And I bet other dozens times, but I'm not much of a PM indexer, while I remember that thread for having taken part to it.)

Re: Perl One Liner to Check Location of a Module
by ferreira (Chaplain) on Apr 09, 2007 at 14:53 UTC
    Install Module::Which and say
    $ which_pm Foo::Bar Foo::Bar (not found)
    or
    $ which_pm DateTime File::Slurp -w 0 DateTime 0.35 /usr/local/lib/perl5/site_perl/5.8.8/c +ygwin/DateTime.pm File::Slurp 9999.12 /usr/local/lib/perl5/site_perl/5.8.8/F +ile/Slurp.pm
    or
    $ which_pm Business:: --p5p Business::BR 0.00_08 at ${installsitelib}/ Business::BR::PIS 0.00_16 at ${installsitelib}/ Business::BR::Ids 0.00_16 at ${installsitelib}/ Business::BR::Biz 0.00_09 at ${installsitelib}/ Business::BR::IE 0.00_16 at ${installsitelib}/ Business::BR::CNPJ 0.00_16 at ${installsitelib}/ Business::BR::CPF 0.00_16 at ${installsitelib}/ Business::BR::Ids::Common 0.00_16 at ${installsitelib}/ from Config: installsitelib: /usr/local/lib/perl5/site_perl/5.8.8
Re: Perl One Liner to Check Location of a Module
by j3 (Friar) on Apr 09, 2007 at 15:10 UTC
    Just remembered, there's also pmtools.
Re: Perl One Liner to Check Location of a Module
by j3 (Friar) on Apr 09, 2007 at 14:59 UTC
    "locate Foo/Bar.pm" can also come in handy sometimes, though, of course, just because locate can find something doesn't mean perl can.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found