如何在 Perl 数组中搜索匹配的字符串? [英] How do I search a Perl array for a matching string?

查看:29
本文介绍了如何在 Perl 数组中搜索匹配的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Perl 中通过字符串数组搜索匹配字符串的最聪明方法是什么?

What is the smartest way of searching through an array of strings for a matching string in Perl?

一个警告,我希望搜索不区分大小写

One caveat, I would like the search to be case-insensitive

所以 "aAa" 将在 ("aaa","bbb")

推荐答案

我猜

@foo = ("aAa", "bbb");
@bar = grep(/^aaa/i, @foo);
print join ",",@bar;

会成功.

这篇关于如何在 Perl 数组中搜索匹配的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆