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.
我有一个 perl 数组,其中不应包含超过 20 个字符的内容。但是,有时会错误地输入更长的字符串。
如何“清除”这些较长字符串的 perl 数组?有没有办法grep长度?就像是..
@blurbs = grep([size<=20],@blurbs);
length获取字符串的长度。
length
@blurbs = grep { length($_) <= 20 } @blurbs;
另一种方法是使用地图
这是一个例子:
my @clean = map { length($_) <= 20 ? $_ : () } @blurbs;