In Perl, is there a built in way to compare two arrays for equality?
Posted
by
Bill
on Stack Overflow
See other posts from Stack Overflow
or by Bill
Published on 2009-10-22T19:33:22Z
Indexed on
2011/12/01
1:49 UTC
Read the original article
Hit count: 150
I have two arrays of strings that I would like to compare for equality:
my @array1 = ("part1", "part2", "part3", "part4");
my @array2 = ("part1", "PART2", "part3", "part4");
Is there a built-in way to compare arrays like there is for scalars? I tried:
if (@array1 == @array2) {...}
but it just evaluated each array in scalar context, and so compared the length of each array.
I can roll my own function to do it, but it seems like such a low-level operation that there should be a built-in way to do it. Is there?
Edit: sadly, I don't have access to 5.10+ or optional components.
© Stack Overflow or respective owner