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.


In reply to Just wanted to post my findings about "use VERSION" or "use 5.010". by Perl300

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.