tjwrona1992 tjwrona1992 - 1 year ago 59
Perl Question

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

I've read that it's considered good practice to always include a

number in all of your Perl scripts, but I never fully understood the purpose.

What do you really gain by including a version number in your script?

Answer Source

Only modules, and only those pushed to CPAN really benefit from specifying $VERSION. There's not much use for it in a script except to use a familiar name rather than inventing a new one if you want the script's version to be accessible.

Primary uses:

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

  • cpan and cpanm uses it to check if an installed module is of sufficiently high level to meet the required minimum version of a dependency.

As brian d foy mentioned, it can also be checked by use Foo 1.23;, but most people avoid this in favour of specifying the required versions of dependencies in their distribution's META file. This allows cpan and cpanm to update the dependency if needed (where use using use Foo 1.23; would cause the installation to fail during testing). Due to the lack of use of the feature, it's hardly a primary use.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download