Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Right -- I have something quite similar (but a little shorter ;) in my .bashrc:
pmversion () { perl -M$1 -le "print $1->VERSION" }
Note that bash interpolates both instances of "$1" before perl gets to read the script.

Also, since I tend to work in a rather "diversified" network environment, it's useful to be able to spot the path to a given module:

pmpath () { perl -M$1 -le "print \$INC{'$'}" }
Here, I have to guard (escape) the "$" in front of INC so the shell leaves it as-is and perl sees it as "$INC"; bash ignores the single-quotes because they're inside "...", and perl does the right thing there, because $1 has already been interpolated by the shell.

UPDATE: The "pmpath" approach above only works for "top-level" modules. In order to get the path for a module like "Foo::Bar::Baz", it's a bit more complicated:

pmpath () { perl -M$1 -le "(\$_='$1')=~s{::}{/}g; print \$INC{\$_.'.pm'}" }
My apologies for the misleading initial version.

FINAL UPDATE: There's actually a much better method for finding the path to a module, as pointed out by Your Mother below.

In reply to Re: oneliner to get module version by graff
in thread oneliner to get module version by sflitman

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2020-09-20 12:30 GMT
    Find Nodes?
      Voting Booth?
      If at first I donít succeed, I Ö

      Results (121 votes). Check out past polls.