But how about the reverse case?
Suppose I write code on my desktop, which has perl 5.10.0 installed, and
later transfer that code to a system that only has perl as far as 5.8.8.
How can I cause an error on the desktop if I accidentally use any of the
new features of 5.10.0, as I would want to do to signal incompatibility?
Is this sort of thing impossible?
> I understand that one can specify that a script must be run under a perl
> version no earlier than a particular version. So, if I say 'use 5.6.0',
> that code will throw an error if one tries to run it under perl 5.5.0,
> right?
#!/usr/local/bin/perl
use warnings;
use 5.6.0;
v-string in use/require non-portable at ./usenet-2008-5-11.pl line 5.
So you have to say
use 5.006;
> But how about the reverse case?
>
> Suppose I write code on my desktop, which has perl 5.10.0 installed, and
> later transfer that code to a system that only has perl as far as 5.8.8.
> How can I cause an error on the desktop if I accidentally use any of the
> new features of 5.10.0, as I would want to do to signal incompatibility?
> Is this sort of thing impossible?
I believe the new features are all turned off by default anyway, so you
have to "use 5.010;" anyway:
#!/usr/local/bin/perl
use warnings;
use 5.010;
say "say say what you want";
Thank you; I do need to specify the 5.10.0 features. But I can use
either 5.10.0 or 5.010 to do so. At least on my system, using
strawberry; see below. Why is it different for you?
------ start quote -----
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
c:\>perl
say "hi";
String found where operator expected at - line 1, near "say "hi""
(Do you need to predeclare say?)
^D
syntax error at - line 1, near "say "hi""
Execution of - aborted due to compilation errors.
c:\>perl
use 5.10.0;
say "hi";
^D
hi
c:\>perl
use 5.010;
say "hi"
^D
hi
c:\>perl
use 5.6.0;
print "hi\n";
^D
hi
c:\>
----------- end quote
It isn't, but "5.010" is backwards compatible with even very old
versions of Perl. The version string "5.10.0" is only recognized
starting with Perl version 5.6.
For the more general case there's the module Perl::MinimumVersion which
attempts to scan your source code and determine the minimum version of
Perl that is needed to run it. It's still in early development though.
Personally, I keep a cheat-sheet of which things (that I commonly use)
were added with each version of Perl. I created it by reading through
the perldelta pages in perldoc.
-mjc
>I believe the new features are all turned off by default anyway, so you
>have to "use 5.010;" anyway:
On what versions of perl5 do you believe has new features off by default? I
have always studied simply just perl5 programming and I have so far never
bumped in situation where my version of perl did not have some feature I use
off by default or feature of newer perl version and I have never paid
attention on if something I learn and then use is feature in perl5 version
newer than this or that so I don't know where to even look for if my code has
any other requirements than that it's not older than perl5 that is used to run
it...
If there is any program available that can check through piece of code and
report any features that are new features of some subversion of perl5 and list
those it finds with of course the version of perl5 that has the feature?
Or am I safe to assume that users with older perl5 version that I have tested
my code with can run my program if I dont have any "use 5.xxx;" line and the
script runs fine?
--
***/--- Sir Robin (aka Jani Saksa) Bi-Sex and proud of it! ---\***
**/ email: rob...@fiveam.NO-SPAM.org, <*> Reg. Linux user #290577 \**
*| Me, Drugs, DooM, Photos, Writings... http://soul.fiveam.org/robsku |*
**\--- GSM/SMS: +358 44 927 3992 ---/**
"Jokainen linkki, jonka päätteenä on ".org", on kelvoton tiedonlähde."
- Nikolas Mäki
In 5.10 you have to explicitely enable new features by adding a
"use 5.010;" line.
> I have always studied simply just perl5 programming and I have so far
> never bumped in situation where my version of perl did not have some
> feature I use off by default or feature of newer perl version and I
> have never paid attention on if something I learn and then use is
> feature in perl5 version newer than this or that so I don't know where
> to even look for if my code has any other requirements than that it's
> not older than perl5 that is used to run it...
I take a pragmatic approach there. I just write my programs for whatever
version of Perl I have available. When I notice that it doesn't work on
some older version (that's what test suites are for - among other
things) I either fix it or add a "use 5.xxx" for the oldest version
where it is known to work.
> If there is any program available that can check through piece of code and
> report any features that are new features of some subversion of perl5 and list
> those it finds with of course the version of perl5 that has the feature?
>
> Or am I safe to assume that users with older perl5 version that I have tested
> my code with can run my program if I dont have any "use 5.xxx;" line and the
> script runs fine?
It depends on your programming style, of course. For my code it is safe
to assume that it won't run with Perl 5.6.x or older unless I specially
took care to make it portable. There were a lot of nifty features added
in 5.8 and I am using them.
I haven't started using 5.10 features yet. All of my servers have some
variant of 5.8.x installed, and until a significant portion of them has
been upgraded to 5.10.x (which I expect to come with the next release
of RHEL and Debian - but we won't upgrade all our servers immediately
even then) using 5.10 features is just a waste of time.
hp
PJH> On 2008-05-12 08:45, Sir Robin <rob...@NO-SPAM-REMOVE-THIS.fiveam.org> wrote:
>> On Sun, 11 May 2008 11:06:21 +0000 (UTC), Ben Bullock
>> <benkasmi...@gmail.com> wrote:
>>> I believe the new features are all turned off by default anyway, so you
>>> have to "use 5.010;" anyway:
>>
>> On what versions of perl5 do you believe has new features off by default?
PJH> In 5.10 you have to explicitely enable new features by adding a
PJH> "use 5.010;" line.
PJH> It depends on your programming style, of course. For my code it is safe
PJH> to assume that it won't run with Perl 5.6.x or older unless I specially
PJH> took care to make it portable. There were a lot of nifty features added
PJH> in 5.8 and I am using them.
i haven't played with 5.10 yet and 5.8 didn't make major syntax
improvements that i want (though it is the default version i generally
use). but for some of my cpan modules (file::slurp) in particular) i
work hard to keep it backwards compatible all the way back to 5.005 (and
i think even 5.004). this is because it is a very popular module and
there are still too many places where old perl's lurk. i wouldn't do
this for any production code where i know the perl version is recent but
i can't control that when someone uses a module.
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
The reverse case is pretty easy:
BEGIN {
die "Your Perl version is too new" if $] > 5.008008;
}
<> Suppose I write code on my desktop, which has perl 5.10.0 installed, and
<> later transfer that code to a system that only has perl as far as 5.8.8.
<> How can I cause an error on the desktop if I accidentally use any of the
<> new features of 5.10.0, as I would want to do to signal incompatibility?
That's not the reverse case.
<> Is this sort of thing impossible?
Basically, yes. There are some new features that aren't available unless
turned on explicitely, but that isn't the case for features that will not
cause any backwards compatability issues. For instance, there are a ton of
new features when using regexpes, and you get them regardless whether you
use "use feature" or not. Furthermore, bug fixes will be there as well, and
so will any modules that are in 5.010, but not in an older install of Perl.
The best way to avoid accidentily using features that aren't available on
older Perl is to install the oldest Perl you want to develop for, and test
with that.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
Yes, that seems to work:
$ perl5.10.0 -e 'print $]'
5.010000
$ perl5.8.8 -e 'print $]'
5.008008
$ perl5.8.2 -e 'print $]'
5.008002
$ perl5.8.0 -e 'print $]'
5.008
$ perl5.6.1 -e 'print $]'
5.006001
Little question: Since this is a floating point number, are there any
rounding-error considerations when making comparisons and such?
Also, is there a reason why 5.10's output pads zeros on the right-hand
end of the number?
--
szr
s> $ perl5.10.0 -e 'print $]'
s> 5.010000
s> $ perl5.8.8 -e 'print $]'
s> 5.008008
s> $ perl5.8.2 -e 'print $]'
s> 5.008002
s> $ perl5.8.0 -e 'print $]'
s> 5.008
s> $ perl5.6.1 -e 'print $]'
s> 5.006001
s> Little question: Since this is a floating point number, are there any
s> rounding-error considerations when making comparisons and such?
those are all well within the float range but i bet they really are
strings. you can check this with some stuff in scalar::util.
s> Also, is there a reason why 5.10's output pads zeros on the right-hand
s> end of the number?
that is obvious. there is room for a subrelease number (as in all the
5.8 versions). 5.10.2 will likely have $] as 5.010002
I'll do that.
> s> Also, is there a reason why 5.10's output pads zeros on the
> right-hand s> end of the number?
>
> that is obvious. there is room for a subrelease number (as in all the
> 5.8 versions). 5.10.2 will likely have $] as 5.010002
Well, look at the output I posted; the one for 5.8.0 was 5.0008 (no
right-hand padding) while 5.10.0 is padded. I wanted to know why there
is a discrepancy?
--
szr
>On 2008-05-12 08:45, Sir Robin <rob...@NO-SPAM-REMOVE-THIS.fiveam.org> wrote:
>> On Sun, 11 May 2008 11:06:21 +0000 (UTC), Ben Bullock
>><benkasmi...@gmail.com> wrote:
>>>I believe the new features are all turned off by default anyway, so you
>>>have to "use 5.010;" anyway:
>>
>> On what versions of perl5 do you believe has new features off by default?
>
>In 5.10 you have to explicitely enable new features by adding a
>"use 5.010;" line.
Too bad that they didn't come up with this, hmm, let's say somewhere around
when 5.6.x came, that would have resulted in all my perl code beeing certainly
working with the version mentioned with 'use' - because now that I have given
thought to it I am quite confident on one single thing of this subject and
that is I started with perl 5.6.x, so... So having now checked "Whats New in
5.6.0" list of new stuff I'd say that if I one day install couple older
versions of perl5 to examine if my scripts/apps needs newer version than
whatever I have I pretty much know that theres not much point to test most of
the scripts with anythin before 5.6.0.. well at least not much before.
>> I have always studied simply just perl5 programming and I have so far
>> never bumped in situation where my version of perl did not have some
>> feature I use off by default or feature of newer perl version and I
>> have never paid attention on if something I learn and then use is
>> feature in perl5 version newer than this or that so I don't know where
>> to even look for if my code has any other requirements than that it's
>> not older than perl5 that is used to run it...
>
>I take a pragmatic approach there. I just write my programs for whatever
>version of Perl I have available. When I notice that it doesn't work on
>some older version (that's what test suites are for - among other
>things) I either fix it or add a "use 5.xxx" for the oldest version
>where it is known to work.
Doesnt sound like a bad and stressful way... But I then again often try to be
perfect on matters with little meaning, I could propably spend quite some time
to check through every version of perl and test them all when I start to go a
bit nutty :D
>It depends on your programming style, of course. For my code it is safe
>to assume that it won't run with Perl 5.6.x or older unless I specially
>took care to make it portable. There were a lot of nifty features added
>in 5.8 and I am using them.
>
>I haven't started using 5.10 features yet. All of my servers have some
>variant of 5.8.x installed, and until a significant portion of them has
>been upgraded to 5.10.x (which I expect to come with the next release
>of RHEL and Debian - but we won't upgrade all our servers immediately
>even then) using 5.10 features is just a waste of time.
I have to learn about them features... You know I still know apparently perl
enough to be able to learn fast what I dont remember... but I'm bad enough to
still get frequently surprised and confused and thinking about beatles coming
to town.
--
***/--- Sir Robin (aka Jani Saksa) Bi-Sex and proud of it! ---\***
**/ email: rob...@fiveam.NO-SPAM.org, <*> Reg. Linux user #290577 \**
*| Me, Drugs, DooM, Photos, Writings... http://soul.fiveam.org/robsku |*
**\--- GSM/SMS: +358 44 927 3992 ---/**
"Kun nuorille opetetaan, että kannabis on yhtä vaarallista kuin heroiini,
niin tokihan he oppivat, että heroiini on yhtä vaaratonta kuin kannabis."
Perl 5.6.0 is old enough that there's generally not much point in
testing with anything older. Authors of CPAN modules might want to
support older versions but for typical programmers it's a waste
of effort.
> I could propably spend quite some time to check through every version
> of perl and test them all when I start to go a bit nutty :D
Don't. You only need to support the environments you're developing for.
If you can count on v5.x installed use it and take advantage of whatever
features it has to offer. There's no point in pursuing backward
compatibility for its own sake.
-mjc
> _
>du...@phony.info (du...@phony.info) wrote on VCCCLXVII September MCMXCIII
>in <URL:news:0gqc245d164jqt67q...@4ax.com>:
><> I understand that one can specify that a script must be run under a perl
><> version no earlier than a particular version. So, if I say 'use 5.6.0',
><> that code will throw an error if one tries to run it under perl 5.5.0,
><> right?
><>
><> But how about the reverse case?
>
>The reverse case is pretty easy:
>
> BEGIN {
> die "Your Perl version is too new" if $] > 5.008008;
> }
Not what I meant. That would prevent me from doing the development on
the desktop, using 5.10.0, defeating my intent.
BTW, beginning with 5.10.0 one can say "no someversion", which might
someday be of some use, but not now. It throws an error in 5.10.0,
since 5.10.0 is too new, and it throws an error in every other version
too, since it's not recognized. One could say "no 5.10.2", and that
would throw an error if someday 5.10.2 were installed, forcing you to
delete the "no 5.10.2". But what good could that possibly be?
>
><> Suppose I write code on my desktop, which has perl 5.10.0 installed, and
><> later transfer that code to a system that only has perl as far as 5.8.8.
><> How can I cause an error on the desktop if I accidentally use any of the
><> new features of 5.10.0, as I would want to do to signal incompatibility?
>
>That's not the reverse case.
You are right, sorry.
>
><> Is this sort of thing impossible?
>
>
>Basically, yes. There are some new features that aren't available unless
>turned on explicitely, but that isn't the case for features that will not
>cause any backwards compatability issues. For instance, there are a ton of
>new features when using regexpes, and you get them regardless whether you
>use "use feature" or not. Furthermore, bug fixes will be there as well, and
>so will any modules that are in 5.010, but not in an older install of Perl.
>
>The best way to avoid accidentily using features that aren't available on
>older Perl is to install the oldest Perl you want to develop for, and test
>with that.
I was afraid of that. I sure don't want to go back to Active State, and
strawberry is not available with older versions.
Then you may have to compile it yourself.
Abigail
--
perl -wle'print"Кхуф бопфиет Ретм Ибглет"^"\x80"x24'
But 5.6.x didn't come with new keywords that could conflict with a possibly
choosen user defined subroutine. That's why 5.010 has "use feature", to turn
specific features that could break backwards compatability.
,, that would have resulted in all my perl code beeing certain
,, working with the version mentioned with 'use' - because now that I have give
,, thought to it I am quite confident on one single thing of this subject and
,, that is I started with perl 5.6.x, so... So having now checked "Whats New in
,, 5.6.0" list of new stuff I'd say that if I one day install couple older
,, versions of perl5 to examine if my scripts/apps needs newer version than
,, whatever I have I pretty much know that theres not much point to test most o
,, the scripts with anythin before 5.6.0.. well at least not much before.
You are misunderstanding "use feature". 5.010 came with a ton of new
features that will be there regardless of whether you use "use feature"
or not. Out of the many new features, only three of them require "use
feature" (or "use 5.010").
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
>Sir Robin wrote:
>> if I one day install couple older versions of perl5 to examine if my
>> scripts/apps needs newer version than whatever I have I pretty much
>> know that theres not much point to test most of the scripts with
>> anythin before 5.6.0.
>
>Perl 5.6.0 is old enough that there's generally not much point in
>testing with anything older. Authors of CPAN modules might want to
>support older versions but for typical programmers it's a waste
>of effort.
Thanks for the info :)
>> I could propably spend quite some time to check through every version
>> of perl and test them all when I start to go a bit nutty :D
>
>Don't. You only need to support the environments you're developing for.
>If you can count on v5.x installed use it and take advantage of whatever
>features it has to offer. There's no point in pursuing backward
>compatibility for its own sake.
True and I knew that, but thanks anyway :) However some of my programs are for
end-users and some of my perl code are plugins for the irc client Irssi and
are meant for anyone who finds them usefull - as I would ofthen have no idea
on what environments people could be running them I would like to have them
rather more backward compatible than less backward compatible ;)
I would not go beyond certain point on this but I have seen, for example, Unix
shell environments for using Irssi where other software besides Irssi is
sometimes dead old - and the end users of the system can't change that. If
it's not too much trouble then I'd love to make my code so that for example
they could use it...
>-mjc
--
***/--- Sir Robin (aka Jani Saksa) Bi-Sex and proud of it! ---\***
**/ email: rob...@fiveam.NO-SPAM.org, <*> Reg. Linux user #290577 \**
*| Me, Drugs, DooM, Photos, Writings... http://soul.fiveam.org/robsku |*
**\--- GSM/SMS: +358 44 927 3992 ---/**
>,, that would have resulted in all my perl code beeing certain
>,, working with the version mentioned with 'use' - because now that I have give
>,, thought to it I am quite confident on one single thing of this subject and
>,, that is I started with perl 5.6.x, so... So having now checked "Whats New in
>,, 5.6.0" list of new stuff I'd say that if I one day install couple older
>,, versions of perl5 to examine if my scripts/apps needs newer version than
>,, whatever I have I pretty much know that theres not much point to test most o
>,, the scripts with anythin before 5.6.0.. well at least not much before.
>
>You are misunderstanding "use feature". 5.010 came with a ton of new
>features that will be there regardless of whether you use "use feature"
>or not. Out of the many new features, only three of them require "use
>feature" (or "use 5.010").
Ok, thank you very much for clearing this up for me :)
>Abigail
--
***/--- Sir Robin (aka Jani Saksa) Bi-Sex and proud of it! ---\***
**/ email: rob...@fiveam.NO-SPAM.org, <*> Reg. Linux user #290577 \**
*| Me, Drugs, DooM, Photos, Writings... http://soul.fiveam.org/robsku |*
**\--- GSM/SMS: +358 44 927 3992 ---/**