#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Posts
    2,232
    Rep Power
    1296
    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"; 
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Wink


    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!!

IMN logo majestic logo threadwatch logo seochat tools logo