Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Identical Arrays

by Athanasius (Chancellor)
on Aug 26, 2012 at 03:07 UTC ( #989776=note: print w/replies, xml ) Need Help??

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; }


The arrays are the same The arrays are different

Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989776]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-10-27 00:20 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (350 votes). Check out past polls.