我有一个包含 (head , b , v , . , b, v, end) 的数组。
我尝试找到并获取“.”,然后做某事(例如:打印出来)。
由于未知的原因,我无法得到“。”
所以我做了一个简单的代码来计算数组中 char 的出现次数。 这是代码:
$stylefile="log2.style";
open ("styles", $stylefile) or die ("can't open file");
while (<styles>)
{
$temp = $_;
chomp($temp);
push @style,$temp;
}
print @style;
# here is the array "headbv.bvend"
@bar = grep(/v/i, @style);
print @bar;
# it prints out vv
@fullstop = grep(/./i, @style);
# it prints out the entire array values.
有任何关于如何获取“.”出现的线索吗? ?
最佳答案
使用 /[.]/
而不是 /./
来匹配句号。
man perlre了解更多详情。
关于arrays - Perl:无法打印数组中出现的字符串 ".",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22527953/