Perl:查找数组的特定元素是单词还是句子 [英] Perl: find whether an particular element of array is a word or sentence
本文介绍了Perl:查找数组的特定元素是单词还是句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含文本文件的数组...那么如何使用 perl 查找仅包含一个单词的数组元素?
I have an array which contains text file ...so how to find the array elements which contain just one word by using perl?
推荐答案
假设文件内容存储在 @lines
Let's say file content is stored in @lines
my @words = grep /^\S+$/, @lines;
<小时>
注意:在进一步处理之前不要忘记chomp @lines;
.
Note : Don't forget chomp @lines;
before any further processing.
这篇关于Perl:查找数组的特定元素是单词还是句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文