Alex Rivera | Logout

What's the modern way of declaring which version of Perl to use?

Asked 2009-12-10T01:25:44.787
20

When it come to saying what version of Perl we need for our scripts, we've got options, oh, brother, we've got options:

use 5.010;
use 5.010_001;
use 5.10.0;
use v5.10;
use v5.10.0;

All seem to work. perlcritic complains about all but the first two. (It's unfortunate that the v strings seem to have such flaws, since Perl 6 expects you to do use v6; for your Perl 6 scripts...)

So, what should we be doing to indicate that we want to use a particular version of perl?

Edit
Report

1 Answer

5

The "modern" way is to use the forms starting with v. However, that may not necessarily be what you really want to do.

Critic complains because older versions of Perl won't understand and play nicely with the forms that start with v. However, if your version of Perl supports it, v is nicer to read because you can say:

use v5.10.1;

... rather than ...

use 5.010_001;

So, in the documentation for use, the following workaround is offered:

use 5.006; use v5.6.1;

NB: I think the documenation is in error here, as the v is omitted from the example at perldoc use.

Since the versions of Perl that don't support the v syntax will fail at the first use, they won't get to the second more specific and readable one.

answered 2009-12-10T02:30:47.973

Your Answer