【发布时间】:2016-10-21 20:22:12
【问题描述】:
我不知道为什么在 Perl 中小事对我不起作用。我对此感到抱歉。
我已经尝试了大约 2 小时,但我无法得到结果。
my $technologies = 'json.jquery..,php.linux.';
my @techarray = split(',',$technologies);
#my @techarray = [
# 'json.jquery..',
# 'php.linux.'
# ];
my $search_id = 'json.jquery..';
check_val(@techarray, $search_id);
我正在做一个“如果”来搜索数组中的上述项目。但它不适合我。
sub check_val{
my @techarray = shift;
my $search_id = shift;
if (grep {$_ eq $search_id} @techarray) {
print "It is there \n";
}else{
print "It is not there \n";
}
}
输出:它总是处于 else 条件并返回“它不存在!” :(
任何想法。我完成了任何愚蠢的错误吗?
【问题讨论】:
-
将您的数组分配更改为:
my @techarray = ('json.jquery..', 'php.linux.'); -
@techarray 是“split”方法的输出。
-
如果你的问题不能像问题中写的那样重现,那么你需要创建一个正确的minimal reproducible example。
-
你能解释一下这是什么意思吗,
@techarray是“split”方法的输出? -
@zdim。我刚刚更新了拆分方法的问题。