在Perl中尝试打印数组的一部分并替换同一数组中的另一个字符串
我是Perl新手,正在尝试编写一个脚本来执行以下操作 我有一个数组,基本上是一个命令的输出在Perl中尝试打印数组的一部分并替换同一数组中的另一个字符串,perl,Perl,我是Perl新手,正在尝试编写一个脚本来执行以下操作 我有一个数组,基本上是一个命令的输出 BIP: Message flow 'Message Flow name' on execution group 'EG' is running.(There are bunch of similar lines) 因此,我使用foreach$(@array name)来读取每一行 现在我只需要数组中的消息流名称,并希望将running更改为started。在行动中也要做到这一点。 所以,我想得到: M
BIP: Message flow 'Message Flow name' on execution group 'EG' is running.(There are bunch of similar lines)
因此,我使用foreach$(@array name)
来读取每一行
现在我只需要数组中的消息流名称,并希望将running更改为started。在行动中也要做到这一点。
所以,我想得到:
Message Flow Name,started as my OP.
你能帮忙吗?
我尝试了拼接
,拆分
,但没有用
提前谢谢。试试这个
#!/usr/bin/perl
use strict;
use warnings;
my @messages = ("BIP: Message flow 'Name1' on execution group 'EG' is running", "BIP: Message flow 'Name2' on execution group 'EG' is running");
for (@messages) {
if (/BIP: Message flow '(.*?)' .* running/) {
print("$1 started as my OP\n");
}
}
一些
您的代码
失败了,一些示例输入
和示例所需输出
怎么样?请尝试regex而不是splice和split谢谢。我会尝试一下。这很有效。非常感谢你的及时帮助。