http://www.perlmonks.org?node_id=989776


in reply to Identical Arrays

See the FAQ How do I test whether two arrays or hashes are equal?.

Update: If the array elements are numeric, this will work:

#! perl use v5.10; use strict; use warnings; my @a = (1, 2, 3); my @b = (2, 3, 1); my @c = (1, 2, 4); printf "The arrays are %s\n", identical(\@a, \@b) ? 'the same' : 'diff +erent'; printf "The arrays are %s\n", identical(\@a, \@c) ? 'the same' : 'diff +erent'; sub identical { my @aa = sort { $a <=> $b } @{ $_[0] }; my @bb = sort { $a <=> $b } @{ $_[1] }; return @aa ~~ @bb; }

Output:

The arrays are the same The arrays are different

Athanasius <°(((><contra mundum