Home / Alt manpages / perl5200delta(1)

  • perl5200delta(1)
  • User command
  • linux

Test Your Scripts Against perl5200delta Safely

Moving a codebase from Perl 5.18 to 5.20 without reading perl5200delta first is how a working pipeline suddenly starts splitting fields the wrong way. This guide turns that document into a small compatibility check covering version reporting, the new key and value slice syntax, experimental signatures, the -F command-line shortcut, Unicode matching and the boundary around rand. Allow about 15 minutes, plus time to run the checks with the oldest Perl version you still support.

This guide uses the installed perl5200delta manual from the perl-doc package, version 5.38.2-3.2ubuntu0.6. The manual itself describes the historical change from Perl 5.18.0 to Perl 5.20.0. A current interpreter can accept some of the syntax differently, so checking your own interpreter's version is part of the result, not a detail to skip.

1. Record the interpreter you are testing

Ask both the shell and Perl which executable and release are actually in play:

$ command -v perl
/usr/bin/perl
$ perl -e 'printf "%vd\n", $^V'
v5.38.2
$ dpkg-query -W -f='${Package} ${Version}\n' perl perl-doc
perl 5.38.2-3.2ubuntu0.6
perl-doc 5.38.2-3.2ubuntu0.6

Your paths and package revision may differ; keep this output with the test result. perl5200delta is a release-change document, not a command that upgrades Perl, selects another interpreter or proves an application is compatible.

Checkpoint

If command -v perl points at a virtual environment, container or user-installed tree, repeat the checks with the exact interpreter used by the service or job.

2. Exercise key and value slices

Perl 5.20 added %hash{...} and %array[...] forms for pulling key/value or index/value pairs. Use a small assertion instead of eyeballing a printed list:

$ perl -e '
use strict;
use warnings;
my %colour = (sky => "blue", grass => "green");
my @pair = %colour{"sky", "grass"};
die "unexpected slice\n" unless @pair == 4;
print join(" ", @pair), "\n";
'
blue sky green grass

Hash order is not a contract, so the useful check is the count of returned values and the presence of the expected keys and values, not their displayed order. In a real test suite, compare the pairs as a hash or sort a normalised representation instead.

Do not confuse this with the older scalar slice form, which returns values for selected keys; the percent form is specifically for pairs. When shell quoting gets in the way, drop the test into a temporary file:

$ perl -c slice-check.pl
slice-check.pl syntax OK

No elevated privilege is needed anywhere here. The command only parses and runs an in-memory example.

3. Try signatures with their compatibility warning in mind

The 5.20 manual calls subroutine signatures experimental and non-default. They unpack arguments into lexical variables and check the argument count, but they are not merely a shorter spelling for assigning @_:

$ perl -e '
use feature "signatures";
no warnings "experimental::signatures";
sub join_words ($first, $second) { return "$first $second" }
print join_words("red", "kite"), "\n";
'
red kite

The no warnings line only quiets the example on interpreters that still flag signatures as experimental; it does not make the syntax available on an older interpreter. Check the version before shipping code that relies on this, and run your test suite on the oldest release you support.

To find the arity boundary, call the function with one argument in a disposable check:

$ perl -e 'use feature "signatures"; sub f ($x, $y) { $x + $y }; f(1)'
Not enough arguments for subroutine

The exact diagnostic can include a file and line number; the non-zero exit status is the part that matters. Do not reach for signatures in a shared module just because the syntax works on your workstation. The module's deployment Perl is the real compatibility boundary.

4. Verify the -F field-splitting shortcut

Perl 5.20 changed the relationship between -F, -a and -n: supplying -F now implies automatic splitting and the implicit input loop. Handy for short pipelines, but it can hide work from anyone unfamiliar with Perl's switches:

$ printf '%s\n' 'Ada,lovelace' 'Grace,hopper' |
    perl -F, -lane 'print $F[1]'
lovelace
hopper

Here -F, sets the split pattern to a comma, -a fills @F, and -n supplies the loop, while -l handles the input record separator and output newline. Use -- before a file name that might start with a hyphen, and quote a regular expression when it contains shell metacharacters.

For a script that will outlive one command line, write the loop out explicitly. It is easier to review, extend and test later:

while (<STDIN>) {
    chomp;
    my ($name, $value) = split /,/, $_, 2;
    print "$value\n";
}

Neither form touches the input file. Redirecting output? Pick a new destination or use a temporary file and rename it only after the command succeeds; shell redirection with > truncates an existing destination before Perl even starts.

5. Check Unicode matching and the random-number boundary

The release notes document Unicode 6.3 support and add \p{Unicode} as a synonym for \p{Any}, matching any Unicode-defined code point. A direct probe keeps the claim narrow:

$ perl -e 'print "match\n" if "A" =~ /\p{Unicode}/'
match

Locale behaviour is a separate matter. The 5.20 document says use locale works with UTF-8 locales, but the result depends on the locale data installed on the host. Do not let a deployment test depend on an unrecorded workstation locale; record locale whenever locale-sensitive matching is in play.

The same document calls Perl's internal rand implementation consistent across platforms, then immediately warns it is not cryptographically secure. Fine for ordinary simulation or test data, not for secrets: use an operating-system or library interface built for cryptographic randomness instead, and review that interface separately.

6. Finish the compatibility pass

Once the small probes pass, run the application's tests with every supported interpreter. Pay particular attention to code relying on exact Data::Dumper output, the deprecated \C regular-expression class, old do SUBROUTINE(LIST) calls, and locale-sensitive behaviour. They are listed in the same manual because a passing feature probe does not clear incompatible code sitting elsewhere.

Do not edit system Perl or install a replacement as part of this check. Missing a required interpreter? Install or select it through your normal packaging and deployment process, then repeat step 1. Keep the original script and test input until the new interpreter has passed the full suite.

Done means

  • The exact Perl executable, interpreter version and package version are recorded.
  • Key/value slices, signatures and the -F shortcut have each been tested with a minimal input.
  • Unicode matching was checked without claiming that rand is suitable for secrets.
  • Locale-sensitive tests record the host locale and do not assume every machine has the same locale data.
  • The full application test suite has run on the oldest supported Perl, with the original files preserved.