Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How do I determine module version in my script?

by LameNerd (Hermit)
on Jul 23, 2003 at 17:03 UTC ( #277250=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,

Thanks for your help with my DBI question. In that node I asked why I was getting a warning when I called DBI->connect() like so ...
DBI->connect( $dbname, $dbuser, $dbpass, $dbd );
The answer is that with the new version of DBI I should call DBI->connect() like this ...
DBI->connect("dbi:$dbd:$dbname", $user, $pass);
Now what I would like to know is how would I go about doing something like this ...
my $DBI_version = getDBI_Version(); if ( $DBI_version > $oldstyle ) { $dbh = DBI->connect("dbi:$dbd:$dbname", $user, $pass); } else { $dbh = DBI->connect( $dbname, $dbuser, $dbpass, $dbd ); }
Does this make any sense? Or am I make this issue too complicated?

Replies are listed 'Best First'.
Re: How do I determine module version in my script?
by NetWallah (Canon) on Jul 23, 2003 at 17:11 UTC
    This works for me, on the command line:
    perl -e "use DBI; print $DBI::VERSION"
    (On WIn32).
    Prints:
    1.37
Re: How do I determine module version in my script?
by moxliukas (Curate) on Jul 23, 2003 at 17:09 UTC

    I have never used DBI, so I don't know if you should get round the interface change in this way. However, to answer your question, most modules keep their version number in a variable $VERSION, so in DBI's case you can get to it via a variable $DBI::VERSION. Here's an example how I got at the CPAN module version:

     perl -MCPAN -e 'print "$CPAN::VERSION\n"'

    Hope this helps

Re: How do I determine module version in my script? ( END{if defined $opt_versions...} )
by ybiC (Prior) on Jul 23, 2003 at 17:33 UTC
    To (hopefully) add even more value to the above fine answers...   the following was gleaned from The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!.   It might not even apply to your situation, yet perhaps still be of value for monks what find your post sometime in the future.
      cheers,
      ybiC

      striving toward Perl Adept
      (it's pronounced "why-bick")
    END{ if(defined $opt_versions){ print "\nModules, Perl, OS, Program info:\n", " Weather::Underground $Weather::Underground::VERSION\n", " Pod::Usage $Pod::Usage::VERSION\n", " Getopt::Long $Getopt::Long::VERSION\n", " strict $strict::VERSION\n", " Perl $]\n", " OS $^O\n", " wunderg.pl $wunderg_VER\n", " $0\n", } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-05-15 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?