perl 判断数组里面是否含有某个元素

2024-11-25 03:23:05
推荐回答(2个)
回答1:

用 grep

$target = "def";
print "Found $target" if ( grep ($target , @x) ) ; #Found def

回答2:

useArray::Compare;my@arr1=0..10;my@arr2=0..10;my$comp1=Array::Compare->;new;if($comp1->;compare(\@arr1,\@arr2)){print"Arraysarethesame\n";}else{print"Arraysaredifferent\n";}