|The stupid question is the question not asked|
Programmatically comparing module version numbersby Anonymous Monk
|on Sep 29, 2008 at 17:27 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
I'm writing a small Perl application, and I have a few questions regarding modules and their version numbers:
1) In order to check whether a module is installed, I currently do the following:
Is there a better way to detect whether the module is there?
Say I've changed the module, it has an error inside, and it won't load properly, but the module is there. Or maybe the user does not have file permissions to read the module file, but the file is. In this case, I would like the application to fail with the right error message, instead of just blindly reporting that the module is not there at all.
2) How do I reliably compare version numbers? I've seen that there are more than one version number formats, I'm not sure if a simple string or a simple numeric compare will do.
This is what I would like to achieve:
That is, I would like some example code for routine is_module_version_at_least.
3) I'm finding the problem that some perl distributions do not ship with some modules by default, and others have older versions. I do not think that the end user should necessarily know how to install modules from CPAN or the like. You need different command-line incantations in order to install modules CPAN under Cygwin (no sudo available), under Debian or under Windows (maybe ActiveState's ppm). A particular application user may not necessarily have root privileges to install modules for all Perl users.
I would like to ship some CPAN module XXX together with my application. If the currently-installed perl has the same or newer version of XXX, I would like to use the already-installed versions. If not, I would like the application to fall-back to the version supplied with it.
How do I achieve that? Or maybe you think of a better approach to distribute applications and modules?
Many thanks, Ruben