tlhackque has asked for the wisdom of the Perl Monks concerning the following question:

A test in a CPAN module that I support is failing on a tester's 5.8.8 install. It passes on mine. Both are linux x86_64, but different distributions. It also passes on many other tester's machines - and this tester's other Perl versions.

The test constructs a string with a series of sprintf()s, then uses Test::More's like() to see if it contains a few key lines. This amounts to a $string =~ qr'^stuff$'ms. Precisely:
like( $string, qr'^-----BEGIN PUBLIC KEY-----$'ms, 'string includes public key PEM' );
I have no clue why this should fail in only one place. This is CPANTS automated testing, so I have no access to the machine.

I don't want to dismiss this as a test artifact in case there's some coding practice that breaks compatibility back to 5.8.8. So I'd like to understand what's going on.

Here is an abbreviated copy of the test report that shows the essentials (note that the ' # ' is added by Test:More and is NOT in the string that's tested).

... # fe5cf495e65e00567724a3964c5f47020301 +0001 # -----BEGIN PUBLIC KEY----- # MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC95h0aRkhNcqBrktxNXzOGgurp +/vkUDFKNda/r # uTMeOlPvXRGIS+kWm8tbahrEXp47bOu1usA7k2EWLQyqm5sdjwXtVyLos5Nw18hG +2acHqbQSV8Zt # YPR8xwpXzZYdFghwVo/Clu3jD1c5Cm0oofZSD/5c9JXmXgBWdySjlkxfRwIDAQAB # -----END PUBLIC KEY----- # keylen : 1024 ... # doesn't match '(?ms-xi:^-----BEGIN PUBLIC KEY-----$)' # Failed test 'string closes public key PEM' # at t/02_base.t line 628. # 'Version : v1

There are 4 instances (subtests) in the test where I inspect this string for (different) strings with this idiom. Even stranger, only 3 of the 4 fail. The full report is at http://www.cpantesters.org/cpan/report/5a7fea9c-8c2a-11e6-a72b-5eeabb799c77?raw=1

The full matrix shows 80 configurations passing...

Any clues would be appreciated. Many thanks!

Replies are listed 'Best First'.
Re: RegExps failing on (some) 5.8.8
by choroba (Cardinal) on Oct 08, 2016 at 17:12 UTC
    I've encountered the same problem and blogged about it. It's a bug in old Perl versions, but read the blog post, I've found a workaround. Flavio's comment points to the corresponding bug report.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Thank you very much for the pointer. Indeed that's the bug that I encountered.

      I installed a 5.8.8 distribution with perlbrew and can now reproduce the issue, which system Perl could not. Apparently my distribution patched this bug.

      Is there a reason that your blog doesn't recommend Flavio's solution of using cloistered modifiers? It seems cleaner and more complete that what your detective work uncovered.

        > Is there a reason that your blog doesn't recommend Flavio's solution

        Well, I wrote the blog post on the 16th of March, the March round of the challenge ended on the last of March, and Flavio replied on the last of May. His reply is there, readable for anybody, but I was too lazy to update the blog post or submit a new pull request.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,