in reply to Re: Comparing arrays
in thread Comparing arrays

That doesn't necessarily work as intended if the values of one or more elements in either array contain the list separator $":

my @array1 = qw(one two three); my @array2 = ("one" . $" . "two", "three"); if ("@array1" eq "@array2") { print 'They are the same', $/; # no, they are NOT }

The updated code is still flawed, consider:

my @array1 = qw(one two three); my @array2 = qw(onetwo three); if ( do{ local $" = ''; "@array1" eq "@array2"} ) { print 'They are the same', $/; # no, they are NOT }

This second update still isn't the way to do it... I took out the local $" (which should be no problem as the value of $" shouldn't matter anyway). Consider:

my @array1 = ("one", "two" . $" . "three"); my @array2 = ("one" . $" . "two", "three"); if ( do{ @array1 == @array2 and "@array1" eq "@array2"} ) { print 'They are the same', $/; # no, they are NOT }

Stringifying would only work if it is guaranteed that $" doesn't occur as a substring of one or more values of either array.

— Arien