|Perl: the Markov chain saw
Ensuring forward compatibilityby DrHyde (Prior)
|on Apr 14, 2004 at 07:54 UTC
Recently in the pub I was talking about forward compatibility between perl5 and perl6 with Nicholas Clark, the current perl 5.8 pumpking. We have been promised that perl6 will also run older perl5 programs, despite quite a lot of incompatible feature changes between the two versions of the language. So how will perl6 be able to tell whether code is written in perl5 or perl6? Or whether it's buggy perl5, correct perl5, buggy perl6, or correct perl6? Heuristics can only get you part of the way, so some kind of explicit marker which definitively says "this is perl5" would be a Good Thing. And it would also be a Good Thing if that mechanism could be used right now in perl5 programs, so that we can start our migration to perl6 by at least ensuring that existing code is forward-compatible.
So I took this to the perl6-language list, suggesting a perl5 pragma "use perl5;" which would be that marker for the perl6 interpreter, but in perl5 would be a null pragma.
However, it turns out that there is already such a mechanism. perl6 will not use the "package" keyword, and will take its presence to mean "this is perl5 code". So existing modules should work already.
But what about scripts and programs? They don't generally say "package" anywhere. But, if you don't specify a package, that just means use the default package, which is called "main". The solution therefore is to insert, at the top of all your scripts and programs, this line:
Go and do it today. Tell your friends. Get yourself ready for the shiny new perl6 world.