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

后端 未结 3 589
猫巷女王i
猫巷女王i 2021-02-01 07:08

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;
u         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 07:31

    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.

提交回复
热议问题