Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在perl中,为什么拆分会在管道处断裂(|)_Perl_Split_Pipe - Fatal编程技术网

在perl中,为什么拆分会在管道处断裂(|)

在perl中,为什么拆分会在管道处断裂(|),perl,split,pipe,Perl,Split,Pipe,在perl中,为什么拆分会在管道处中断(|)。 我必须在“和 my @temp1 = split(/\"/,$line); 但这也会在管道(|)处断裂。就像输入一样 my_string|is"_ok 输出是 mystring , is, _ok 为什么?? 为什么不呢 mystring|, is, _ok 您的程序似乎在其他地方包含错误 运行以下脚本: use strict; use warnings; my $line = 'my_string|is"_ok'; print "Sou

在perl中,为什么拆分会在管道处中断(
|
)。 我必须在

my @temp1 = split(/\"/,$line);
但这也会在管道(
|
)处断裂。就像输入一样

my_string|is"_ok
输出是

mystring ,  is, _ok
为什么?? 为什么不呢

mystring|, is, _ok

您的程序似乎在其他地方包含错误

运行以下脚本:

use strict; use warnings;
my $line = 'my_string|is"_ok';
print "Source: $line\n";
my @temp1 = split(/"/, $line);
print "Result 1:\n";
my $index;
for my $elem (@temp1) {
    print ++$index, ": $elem\n";
}
@temp1 = split(/["|]/, $line);
print "Result 2:\n";
$index = 0;
for my $elem (@temp1) {
    print ++$index, ": $elem\n";
}
您将得到下面给出的结果

Source: my_string|is"_ok
Result 1:
1: my_string|is
2: _ok
Result 2:
1: my_string
2: is
3: _ok
如您所见,该脚本包含两个匹配变量:

  • 正如您所尝试的,仅在双引号上拆分
  • 尝试在其中一个上复制结果-拆分 双引号或竖条
  • 要编写匹配双引号的正则表达式,不需要 逃避它

    请注意,在字符类中(介于
    [
    ]
    之间),您甚至可以 不需要逃离垂直条

    因此,为了保持程序简单易读,避免不必要的错误
    反斜杠。

    不能复制。考虑添加更多细节到您的问题。您在示例中所写的拆分将输出<代码> MySoxSype是,,并且不会拆分“IS”。您确信<代码> $Loe>代码>包含您所期待的吗?