develooper Front page | perl.perl5.porters | Postings from July 2020

Some facts about `use VERSION`

Thread Next
Paul "LeoNerd" Evans
July 3, 2020 20:26
Some facts about `use VERSION`
Message ID:
As it has been getting a lot of mention lately, I thought I'd spend a
few minutes to remind/inform everyone about some facts about perl's
"use VERSION" syntax. Some of this was even new to me either today, or
at least a few days ago, so I fully expect this to be informative to at
least a few people and clear up some misconceptions.

 * The ability to write a version in "v-string" notation has been part
   of core perl since at least 5.6. [March 2000, according to Wikipedia]

     $ perl5.6.2 -e 'use v5.8;'
     Perl v5.8.0 required--this is only v5.6.2, stopped at -e line 1.
     BEGIN failed--compilation aborted at -e line 1.

   At one time these v-strings felt new and strange, and the advice was
   not to use them for fear of back-compat issues. At this point in
   time, unless you need backward compatibility to something older than
   perl 5.6, you have nothing to fear by using a v-string.

   ((I literally didn't know this until today. So far I have code on
     CPAN that defensively does `use 5.026` but now I know this I will
     be changing it all to `use v5.26`))

 * From perl version 5.12 onwards [November 2012], the "use VERSION"
   syntax also implies "use strict". Thus, if you don't need to
   maintain backwards compatibility to any perls older than 5.12, you
   can replace

     use strict;


     use v5.12;

   Not only is that one character shorter to type, it also brings in
   the `say` feature. I don't know about anyone else, but I find that
   extremely useful in small test/debugging situations.

   v5.12 also brings in the `state`, `switch` and `unicode_strings`
   features. The latter of these does alter the behaviour of regexp
   patterns and other string functions with respect to unicode
   characters, so if you are planning to turn this on I would recommend
   reading `perldoc feature` and `perldoc perlunicode` to find out more
   about that before doing so. Quoted here in brief:

       Safest if you "use feature 'unicode_strings'"
           In order to preserve backward compatibility, Perl does not
       turn on full internal Unicode support unless the pragma "use
       featureĀ 'unicode_strings'" is specified.  (This is automatically
       selected if you "useĀ 5.012" or higher.)  Failure to do this can
       trigger unexpected surprises.  See "The "Unicode Bug"" below.

 * In October 2019 an issue was raised requesting that the next
   `use VERSION`, which would be v5.34, also enable the "warnings"
   pragma, much as 5.12 enabled "strict":

   This was debated for a while, with the current prevailing opinion
   being to not do this because enabling "use warnings" just because
   someone requested "use v5.32" was considered too radical and

Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About