gpt4 book ai didi

perl - 现在不再支持 $* 如何用替代方案替换 $*=1

转载 作者:行者123 更新时间:2023-12-01 23:44:39 38 4
gpt4 key购买 nike

我是一个完全的 Perl 新手,正在使用 Perl 5.10 运行 Perl 脚本并收到此警告:

$* is no longer supported at migrate.pl line 380.

任何人都可以描述 $* 做了什么以及现在建议的替代品是什么?或者,如果您可以向我指出描述这一点的文档,那就太好了。

我正在运行的脚本是将源代码数据库从 vss 迁移到 svn,可以在此处找到: http://www.x2systems.com/files/migrate.pl.txt

使用它的两个代码片段是:

    $* = 1;
$/ = ':';

$cmd = $SSCMD . " Dir -I- \"$proj\"";
$_ = `$cmd`;

# what this next expression does is to merge wrapped lines like:
# $/DeviceAuthority/src/com/eclyptic/networkdevicedomain/deviceinterrogator/excep
# tion:
# into:
# $/DeviceAuthority/src/com/eclyptic/networkdevicedomain/deviceinterrogator/exception:
s/\n((\w*\-*\.*\w*\/*)+\:)/$1/g;

$* = 0;

然后是稍后的一些方法:

            $cmd = $SSCMD . " get -GTM -W -I-Y -GL\"$localdir\" -V$version \"$file\" 2>&1";
$out = `$cmd`;

# get rid of stupid VSS warning messages
$* = 1;
$out =~ s/\n?Project.*rebuilt\.//g;
$out =~ s/\n?File.*rebuilt\.//g;
$out =~ s/\n.*was moved out of this project.*rebuilt\.//g;
$out =~ s/\nContinue anyway.*Y//g;
$* = 0;

非常感谢,

  • 罗里

最佳答案

来自perlvar :

Use of $* is deprecated in modern Perl, supplanted by the /s and /m modifiers on pattern matching.

如果您有权访问匹配的位置,只需将其添加到末尾即可:

 $haystack =~ m/.../sm;

如果您只能访问字符串,则可以用

将表达式括起来
 qr/(?ms-ix:$expr)/;

或者根据您的情况:

s/\n((\w*\-*\.*\w*\/*)+\:)/$1/gsm;

关于perl - 现在不再支持 $* 如何用替代方案替换 $*=1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/88518/

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