Skip to content

Instantly share code, notes, and snippets.

@hirose31
Last active January 4, 2016 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirose31/8647156 to your computer and use it in GitHub Desktop.
Save hirose31/8647156 to your computer and use it in GitHub Desktop.
pmver - Utility shell function for checking version of an arbitrary Perl module
$ pmver Carp
1.26
/home/hirose31/perlbrew/perls/perl-5.16.3/lib/5.16.3/Carp.pm
$ pmver -cd Carp
1.26
/home/hirose31/perlbrew/perls/perl-5.16.3/lib/5.16.3/Carp.pm
$ pwd
/home/hirose31/perlbrew/perls/perl-5.16.3/lib/5.16.3
pmver () {
do_cd=
if [ "$1" = '-cd' ]; then
do_cd=1
shift
fi
module=$1
perl -M${module} -e "print \$${module}::VERSION,\"\n\""
fullpath=$(
perldoc -ml ${module} 2>/dev/null
[ $? -eq 255 ] && perldoc -l ${module}
)
echo $fullpath
if [ "$do_cd" = '1' ]; then
\cd $(dirname $fullpath)
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment