Technology news and Jobs
The Linux distillery
Legends of FOSS: Perl 5.10 is here
The Linux distillery
Legends of FOSS: Perl 5.10 is here | Legends of FOSS: Perl 5.10 is here |
|
|
|
| Written by David M Williams | |
| Wednesday, 02 January 2008 | |
|
Page 1 of 3
Backwards compatibility It’s possible for the brand new Perl 5.10 interpreter to be installed without harming existing code. The major new language features must be turned on or else the Perl interpreter will ignore them. This ensures scripts will run as usual without any modifications – but can also be progressively migrated to use the new constructs. There’s three main ways to turn on the new features. A new feature pragma has been introduced; this can turn on one or more of three major syntactic pieces. For instance use feature ‘switch’; enables the new switch construct, which allows program code to inspect a variable or expression and branch in many different paths depending on the result. This pragma can be disabled later in code, if so desired, with a matching line of code: no feature ‘switch’; By surrounding code with use feature / no feature it is possible to progressively upgrade lengthy scripts. Alternatively, enclosing use feature within a block of code (via { } braces) will implicitly execute a no feature pragma at the end of the block. There are three of these significant new language features – switch, say and state. Each can be turned on and off as required, without impacting on the others. A second way to turn on these features is all in one hit. As well as introducing features, Perl 5.10 also introduces the concept of “feature bundles” which will no doubt be used for future releases thereby giving a clean upgrade path all the way to Perl 6. The feature bundle works in pretty much the same way; add a line of code use feature ‘:5.10’; and all the new features up to version 5.10 will be enabled. A colon precedes the version number so it is not confused with the name of an actual feature (like “switch”.) In the future, if point releases come out, the version number “:5.10” will refer to the most current point release; an explicit release can be referenced by adding an additional number, e.g. “:5.10.0” for the current version. Now, all this adding lines of code to make use of new language features may seem a pain. Why litter lovely new code with statements that exist just to benefit old scripts? If you feel this way, the third method to turn on new features might suit you better: run the Perl interpreter from the command line with the –E switch and all new language features are implicitly enabled; there’s no need to do any use feature stuff – it’ll just all be there. So, what actually does switch do – let alone say and state? CONTINUED
|
| < Prev | Next > |
|---|






Subscribe to iTWire's daily e-newsletter now and get a FREE 12 month license to project management software valued at $99 USD. 



