Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
下面的脚本在每个“E”处中断序列,随后在每个片段上添加一个“E”。但是我没有将'E'附加到我的最后一个元素上,为什么?
use strict; use warnings; my $s = 'ABCDEABCDEABCDEABCDEABCDE'; my @a = split /E(?!P)/, $s; my $result = join "E,", @a; my @final = split /,/, $result; print "@final\n";
A在连续元素之间join连接它的第一个参数。如果你想添加最后的“E”,你可以简单地做:
join
$s = 'ABCDEABCDEABCDEABCDEABCDE'; @a = split(/E(?!P)/, $s); print join ("E ", @a), "E\n";
请参阅以下文档split:
split
默认情况下,保留空的前导字段,并删除空的尾随字段。