These are a few idioms I had to change in a series of modules (that already worked in 5.6.x and 5.8.x) in order to make them backwards compatible with Perl 5.005_03.
I hope this can be useful to other module authors that are willing to widen their audience:
| Perl 5.6 and 5.8 | Perl 5.005_03 | See Also |
| our $var; | use vars qw( $var ); | 48350 |
| use warnings; | #!perl -w
doesn't work inside modules | 282957, 278796, 294493 |
| $func_ref[3]($var); | $func_ref[3]->($var); | |
|
reference to an array of aliases: $param_ref = \@_; |
no equivalence. In 5.005_03 it makes a copy, just like: $param_ref = [ @_ ]; | 289445 |
| $_++ for values %hash; | $hash{$_}++ for keys %hash;
or: $_++ for @hash{keys %hash}; | |
| use bytes; |
| 294493 |
|
| DateTime |
| $object->$method; | $object->$method(); | 413389 |
As ajdelore puts it, "this is not because I think that people should continue to use perl 5.005, but simply in acknowledgement of the fact that many people do use perl 5.005".
See also what PodMaster writes on using use VERSION; in "Code should be version-aware".
Update: fixed the "func_ref" bug. Thanks Merlin, autarch; added a reference to Juerd note.
Update: added use bytes.
Update: added open $fh from autarch DateTime code.
Update: be aware that the order of the keys in a hash may change, so you'd better sort the keys if you want repeatable results between versions.
Update (Dec/2004): Added "$_++ for @hash{keys %hash}", seen in CB, from Merlin. Also added $object->$method() and explained better what happens in the $param_ref example.
In reply to Migrating scripts back to Perl 5.005_03 by fglock
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |