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.
要获取包含 / 的字段中元素的索引,我使用以下内容但收到错误消息:
@ind = grep($fields[$_] =~ /\/\/]);
搜索模式未终止
为了完整起见,它应该是这样的(如果有问题的数组是@fields可变的):
@fields
my @slash_indexes = grep { $fields[$_] =~ m~/~ } 0..$#fields;
演示。问题中给出的代码缺少 grep 的第二个参数- 应该被grep的列表。考虑到您需要收集索引,您还需要将原始数组的索引传递给grep,而不是数组本身。
grep
您正在转义/应该终止您的正则表达式的那个。
/
\只需从它之前删除最后一个。
\