October 31st, 2016, 09:20 AM
-
compare between 2 cells of arrays
Hi All
Do we have in Perl something stronger then =~ in order to check equality of 2 strings inside arrays?
I did loop inside loop the first loop is running on the first array - for every cell in this array I check inside the secound array.
when I find match between cell from Array1 to cell from Array2 - I print something.
It works very good till I got bug that even if in the cells I got even part of the string of the other cell - it also give me "true" and do whatever the if statement ask instead of skip the if and continue to the else
example:
Code:
if($Array1[i] =~ $Array2[j]){
print "something...";
}else {
"do something else"
}
if in Array1[i] I have string LIKE
and in Array2[j] I have string IKE
the condition still gave me true although its false and should continue to the else.
Do you know about stronger equality between 2 strings in array?
Thank you very much for your help.
.
Moran
October 31st, 2016, 01:39 PM
-
If you want to test if 2 strings are equal, then you should use the eq equality operator, not a regex.
Code:
if ($Array1[i] eq $Array2[j]) {
print "something...";
}
else {
print "something else";
}
November 2nd, 2016, 07:54 AM
-
Originally Posted by FishMonger
If you want to test if 2 strings are equal, then you should use the
eq equality operator, not a regex.
Code:
if ($Array1[i] eq $Array2[j]) {
print "something...";
}
else {
print "something else";
}
Thank you very much!!
It works!!