xenoterracide
xenoterracide

Reputation: 16865

regex /ms not behaving as expected perl 5.8.8

I have a failing test on 5.8.8, I don't understand why, esp when it works in more recent versions (perhaps it was just a bug) (here's a link to the full code)

use strict;                                                                                                          
use warnings;                                                                                                        
use Test::More;                                                                                                      

my $fname = 'Fo';                                                                                                    

my $content = do { local $/ ; <DATA> };                                                                             
like $content, qr/^$fname $/xms, q[includes first name];                                                             

done_testing;                                                                                                        
__DATA__                                                                                                             
use strict;                                                                                                          
use warnings;                                                                                                        
use Test::More;                                                                                                      

# generated by Dist::Zilla::Plugin::Test::PodSpelling bootstrapped version                                           
eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $@;                                            

add_stopwords(<DATA>);
all_pod_files_spelling_ok('bin', 'lib');
__DATA__
Fo
oer
bar

on all recent versions of perl this works fine. but in 5.8.8 the test fails. I found that by removing the ^ and $ the code works, its like Perls regex engine is ignoring the /m but the documentation says it was supported.

Why does this not work? and what is the most correct way to fix it? (note: I believe that the test should check that these elements are on a line by themselves )

Upvotes: 3

Views: 184

Answers (1)

ikegami
ikegami

Reputation: 386396

This is bug RT#7781. It was fixed in 5.8.9 and 5.10.0.

Workarounds:

  • qr/^/m is equivalent to qr/(?:^|(?<=\n))/
  • qr/$/m is equivalent to qr/(?=\n|\z)/

Upvotes: 3

Related Questions