Perl300 has asked for the wisdom of the Perl Monks concerning the following question:
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:
The demo program Test.pl:/usr/bin/perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
#!/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.
|
|---|