perl glob() changes between versions?

We noticed a perl script which was updated upstream started failing on RHEL6 (v5.10.1) but was fine on RHEL7 (v5.16.3). The author had refactored the code to appear to support file wildcards but had also enclosed the original string in quotation marks ("$string")

UPDATE: Adam Sampson mentioned that this change was made in Perl 5.15.5

A bit of digging showed that perl’s glob() function appears to have changed behaviour at some point between these versions.

Given the following test script:

$f = $ARGV[0];
$f2 = '"' . $f . '"';
@fl = glob($f2);
print Dumper($f, $f2, \@fl);

This produces differing results:

rhel6$ perl -MData::Dumper testscript a
$VAR1 = 'a';
$VAR2 = '"a"';
$VAR3 = [
          '"a"' <-- here
        ];


rhel7$ perl -MData::Dumper testscript a
$VAR1 = 'a';
$VAR2 = '"a"';
$VAR3 = [
          'a' <-- here
        ];

The final array output ought to be the same, but it's not. The scripts next check was to test for the file's existence which, given it now has quotation marks around it, just doesn't work in RHEL6 🙂

Leave a Reply