Perl300 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Recently I came across a situation where I was using v5.10.1 and tried "say" instead of "print" without adding "use 5.010". I got syntax error for line with "say" which went away when I added "use 5.010". I was little confused as to why I should have to include "use 5.010" when I was already using v5.10.1.

So when I did some search I found following which I want to share here so others like me can find it quickly, here (by searching for either "use VERSION" or "use 5.010"). Another motive is if there's anything I missed to find, I might know from the comments from the wise ones here.

The version of perl I am on:

/usr/bin/perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
The demo program Test.pl:
#!/usr/bin/perl #use 5.010; say "Cheese!";

Compilation error: syntax error at Test.pl line 5, near "say "Cheese!"". If you add "use 5.010" by uncommenting line 3 then the compilation error goes away.

Reason behind the error is: It's only necessary to add "use 5.010" if you want a new feature from version 5.010 that might cause compatibility issues with code written for previous versions of Perl. For instance, the 'print' is always available, but the 'say' was newly added with 5.010. So, in a case if you have some old code that uses a sub called 'say' it would work without any issues even if you upgrade from any older version to 5.010 if you don't explicitly add "use 5.010". And at the same time you won't be able to use "say" instead of "print" even if you are on version 5.010 if you don't explicitly add "use 5.010"

So in a nutshell, upgrading to new versions was made as simple as possible by adding concept of "use VERSION" which blocks all the newly added features which might cause compatibility issues.

Please let me know if I have missed anything and forgive me for repeating something that was discussed in node use version confusion which is already posted here on PM. I also found link to documentation for use in above node.

Replies are listed 'Best First'.
Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by stevieb (Canon) on May 12, 2016 at 18:13 UTC

    Hi Perl300,

    Note that you can also use the feature pragma to import individual features, as opposed to use $VERSION:

    use feature 'say'; say 'hello, world!';
Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by 1nickt (Canon) on May 12, 2016 at 18:14 UTC

    ++, nice sharing post.

    You can also pull in just a single feature like this:

    #!/usr/bin/perl use strict; use warnings; use feature qw/ say /; ...

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by kcott (Archbishop) on May 13, 2016 at 07:31 UTC

    G'day Perl300,

    ++ on your report.

    For command line work, consider the -E option instead of the -e option (see perlrun: Command Switches):

    Equivalent to what you got without use VERSION:

    $ perl -e 'say 1' Number found where operator expected at -e line 1, near "say 1" (Do you need to predeclare say?) syntax error at -e line 1, near "say 1" Execution of -e aborted due to compilation errors.

    Equivalent to what you got using use VERSION:

    $ perl -E 'say 1' 1

    I'm using:

    $ perl -v This is perl 5, version 22, subversion 0 (v5.22.0) built for darwin-th +read-multi-2level (with 1 registered patch, see perl -V for more detail) ...

    — Ken

Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by choroba (Cardinal) on May 13, 2016 at 11:03 UTC
    There are also features not covered by the feature pragma, see Syntax::Construct for an attempt to handle them systematically.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      I saw this module float by on meta the other day just after v5.24 release. Nice piece of work choroba!

Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by haukex (Archbishop) on May 13, 2016 at 07:53 UTC

    Hi Perl300,

    Just adding this because it hasn't been linked to yet: all the gory details are in feature, esp. at the very bottom of the document, "Implicit Loading".

    Regards,
    -- Hauke D

Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by ikegami (Patriarch) on May 12, 2016 at 18:53 UTC

    [Oops, I thought the OP was asking why it was required. Feel free to ignore this.]

    It was done for backwards compatibility reasons.


    Let's say you wrote the following program for Perl 5.8 (which didn't have a say operator):

    ... sub say { log('info', @_); } say("boo"); ...

    Your program should continue to work if you upgrade to Perl 5.10. Yet upgrading to 5.10 would have broken your program if say didn't require use feature qw( say ); (the relevant part of use 5.010;).

Re: Just wanted to post my findings about "use VERSION" or "use 5.010".
by Perl300 (Friar) on May 12, 2016 at 22:37 UTC
    Thank you all for your comments. And I am glad that I learned about use feature.