What is the real purpose of the $ VERSION variable in Perl?

I read that I thought good practice always included the $VERSION number in all of your Perl scripts, but I never understood the purpose of the goal.

What do you really get by including the version number in your script?

+8
perl version
source share
2 answers

Only modules, and only those that are pressed on CPAN, really benefit from specifying $VERSION . There is not much use for it in a script, except to use a familiar name, and not invent a new one if you want a version of the script to be available.

Primary use:

  • CPAN uses it as a distribution version, allowing it to index different versions of the same distribution.

  • cpan and cpanm use it to verify that the installed module is installed high enough to match the required minimum version of the dependency.

As brian d foy mentioned, it can also be checked with use Foo 1.23; but most people avoid this in favor of specifying the required version of the dependencies in their meta meta data. This allows cpan and cpanm update the dependency if necessary (where use using use Foo 1.23; will cause the installation to fail during testing). Due to the lack of using the function, this is hardly the main advantage.

+8
source share

You can specify the minimum version of the module in the use statement:

  use Foo 1.23; 

When Perl loads this module, it looks at the $VERSION variable to verify that it is equal to or greater than this number. Thus, you get the right set of features and fixes.

CPAN clients use $VERSION to determine whether you have upgraded or install the latest version of the module.

For programs or scripts, you usually don't need $VERSION .

+7
source share

All Articles