逐个字符perl比较两个数组(Comparing two arrays character by character perl)
我有两个数组:
@ Array1包含A,B,C,D,E
和
@ Array2包含L,B,C,F,E
我尝试使用foreach遍历数组中的每个元素,并说是否真的开始但是在做任何事情时我都会遇到肮脏的大胖错误。
该程序与一个foreach完美配合,但是嵌套的它会出错:
foreach my $var (@Array1){ print "Letter $var"; foreach my $var2 (@Array2){ if($var2 eq $var) { print "They are equal"; } else { next; } } }
有任何想法吗; 一个错误是:
在compare.pl第192行,<>第2行的字符串eq中使用未初始化的值。
I have two arrays:
@Array1 which contains A,B,C,D,E
and
@Array2 which contains L,B,C,F,E
I tried using a foreach to go through every element in the arrays and say if it's true or not to get started but I get dirty big fat errors when doing anything.
The program works perfectly with one foreach, but with a nested one it bugs out:
foreach my $var (@Array1){ print "Letter $var"; foreach my $var2 (@Array2){ if($var2 eq $var) { print "They are equal"; } else { next; } } }
Any Ideas; one error is:
Use of uninitialized value in string eq at compare.pl line 192, <> line 2.
原文:https://stackoverflow.com/questions/13462069