gpt4 book ai didi

perl - regex/ms 未按预期运行 perl 5.8.8

转载 作者:行者123 更新时间:2023-12-02 00:20:23 25 4
gpt4 key购买 nike

我在 5.8.8 上有一个失败的测试,我不明白为什么,尤其是当它在更新的版本中工作时(也许这只是一个错误)(这里是 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

在所有最新版本的 perl 上都可以正常工作。但在 5.8.8 中测试失败。我发现通过删除 ^$ 代码可以工作,就像 Perls 正则表达式引擎忽略 /mthe documentation说它得到了支持。

为什么这不起作用?最正确的修复方法是什么? (注意:我认为测试应该检查这些元素自己在一条线上)

最佳答案

这是错误 RT#7781 .它已在 5.8.9 和 5.10.0 中修复。

解决方法:

  • qr/^/m相当于qr/(?:^|(?<=\n))/
  • qr/$/m相当于qr/(?=\n|\z)/

关于perl - regex/ms 未按预期运行 perl 5.8.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11231441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com