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.8Perl 5.005_03See 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;
$INC{ 'bytes.pm' }++ if $] < 5.006; use bytes;
294493
open my $fh, "<$filename" or die "Cannot read $filename: $!";
my $fh = do { local *FH; *FH }; open $fh, "<$filename" or die "Cannot read $filename: $!";
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.