arrays - Perl:无法打印数组中出现的字符串 "."

标签 arrays string perl find-occurrences

我有一个包含 (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/

相关文章:

javascript - 在javascript中按键名对对象数组进行排序

javascript - 如果现有选项均不匹配使用 JavaScript 存在的特定字符串,则向下拉列表添加新选项

python - 从python中为postgresql中的union中的每个查询选择特定列

php - 计算单词数并在变量 php 中插入标签

perl - Perl 中的哈希常量

perl - 为什么 Perl 在 Windows 上会丢失外来字符?这个问题可以解决吗(如果可以,如何解决)?

c++ - 将 m x 3 数组更改为 STL 容器?

c# - 将数组从 C# 返回到 javascript 的最佳(简单且清晰)方法是什么

java - 从字节数组中删除多余的 "empty"字符并转换为字符串

java - 如何通过 Eclipse 在 java 中导入现有的 perl 项目?