Check Perl 5.20 language changes before you upgrade scripts
You will turn perl5200delta into a small compatibility check for scripts moving from Perl 5.18 to 5.20 or later. The checks cover 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.
The route
Jump straight to the step you need, or tick off Done means at the end.
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 the version check is part of the result rather than a detail to skip.
1. Record the interpreter you are testing
Start by asking both the shell and Perl which executable and release are in use:
$ 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 that 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 obtaining key/value or index/value pairs. Use a small assertion instead of judging a printed list by eye:
$ 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. The useful check is the number of returned values and the presence of the expected keys and values, not the displayed order. If this is part of a real test suite, compare the pairs as a hash or sort a normalised representation.
Do not confuse this with the older scalar slice form, which returns values for selected keys. The percent form is specifically for pairs. Keep the test in a temporary file when shell quoting becomes distracting:
$ perl -c slice-check.pl
slice-check.pl syntax OK
No elevated privilege is needed. The command only parses and runs an in-memory example.
3. Try signatures with their compatibility warning in mind
The 5.20 manual describes subroutine signatures as experimental and non-default. They unpack arguments into lexical variables and check the argument count, but they are not merely 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 makes the example quiet on interpreters that still classify signatures as experimental. It does not make the syntax available on an older interpreter. Check the version before shipping code that uses it, and run your test suite on the oldest supported release.
To see 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. A non-zero exit status is the important part. Do not use signatures in a shared module solely because the syntax is available on your workstation; the module's deployment Perl is the 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. This is useful for short pipelines, but it can hide work from a reader 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. The -l switch handles the input record separator and output newline in this example. Use -- before a file name that might begin with a hyphen, and quote a regular expression when it contains shell metacharacters.
For a script that will live longer than one command line, write the loop explicitly. It is easier to review, extend and test:
while (<STDIN>) {
chomp;
my ($name, $value) = split /,/, $_, 2;
print "$value\n";
}
Neither form changes the input file. If you redirect output to a file, choose 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 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 Unicode-defined code points. A direct probe keeps the claim narrow:
$ perl -e 'print "match\n" if "A" =~ /\p{Unicode}/'
match
Locale behaviour is separate. 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 make a deployment test depend on an unrecorded workstation locale. Record locale when locale-sensitive matching matters.
The same document says Perl's internal rand implementation is consistent across platforms, then immediately warns that it is not cryptographically secure. Use it for ordinary simulation or test data only. For secrets, use an operating-system or library interface designed for cryptographic randomness, and review that interface separately.
6. Finish the compatibility pass
After 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. These are listed in the same manual because a successful feature probe does not clear incompatible code elsewhere.
Do not edit system Perl or install a replacement as part of this check. If a required interpreter is missing, 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
-Fshortcut have each been tested with a minimal input. - Unicode matching was checked without claiming that
randis 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.