小编use*_*357的帖子

Perl,将标量与数组进行比较(使用正则表达式?)

我会简短,所以我不浪费你的时间;

简单的问题,我有一堆说,数百只狗

my @dogs = qw(Shepard Lab Dalmation Husky Chow Pitbull ...)
Run Code Online (Sandbox Code Playgroud)

我想把它与一只狗比较

my $doggy = "Shepard";
Run Code Online (Sandbox Code Playgroud)

我知道这很愚蠢,但我怎么办呢?

# Regex match against array?
# (This doesnt even work but its how i would think of doing it)
if ($doggy =~ /@dogs/) {
print $doggy;
}
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的任何答案,我感谢你们帮助我解决可能是一个非常愚蠢的问题.谢谢

regex arrays perl comparison match

3
推荐指数
1
解决办法
4519
查看次数

标签 统计

arrays ×1

comparison ×1

match ×1

perl ×1

regex ×1