I have two arrays, @a and @b. I want to do a compare among the elements of the two arrays.
my @a = qw"abc def efg ghy klm ghn";
my @b = qw"def ghy jgk lom com klm";
If any element matches then set a flag. Is there any simple way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, your 2 arrays need to be written correctly.
Second of all, for arbitrary arrays (e.g. arrays whose elements may be references to other data structures) you can use
Data::Compare.For arrays whose elements are scalar, you can do comparison using
List::MoreUtilspairwise BLOCK ARRAY1 ARRAY2, where BLOCK is your comparison subroutine. You can emulatepairwise(if you don’t have List::MoreUtils access) via:P.S. I am not sure but List::Compare may always sort the lists. I’m not sure if it can do pairwise comparisons.