in reply to oneliner to get module version
Right -- I have something quite similar (but a little shorter ;) in my .bashrc:
Note that bash interpolates both instances of "$1" before perl gets to read the script.pmversion () { perl -M$1 -le "print $1->VERSION" }
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:
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.pmpath () { perl -M$1 -le "print \$INC{'$1.pm'}" }
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:
My apologies for the misleading initial version.pmpath () { perl -M$1 -le "(\$_='$1')=~s{::}{/}g; print \$INC{\$_.'.pm'}" }
FINAL UPDATE: There's actually a much better method for finding the path to a module, as pointed out by Your Mother below.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: oneliner to get module version
by Your Mother (Archbishop) on Jun 15, 2009 at 03:57 UTC | |
by graff (Chancellor) on Jun 15, 2009 at 15:58 UTC | |
Re^2: oneliner to get module version
by sflitman (Hermit) on Jun 15, 2009 at 03:12 UTC |
In Section
Cool Uses for Perl