Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Identical Arrays

by Kenosis (Priest)
on Aug 26, 2012 at 06:33 UTC ( #989792=note: print w/ replies, xml ) Need Help??


in reply to Identical Arrays

Another option is to use Array::Compare, as it can handle alpha, numeric and alphanumeric array data:

use Modern::Perl; use Array::Compare; my @a = ( 1, 2, 3 ); my @b = ( 2, 3, 1 ); my @c = ( 1, 2, 4 ); my @d = qw/ a b c a /; my @e = qw/ a a b c /; my @f = qw/ 1 b c 1 /; my @g = qw/ 1 1 b c /; say 'The arrays are', ArraysIdentical( \@a, \@b ) ? ' ' : ' not ', 'id +entical.'; sub ArraysIdentical { Array::Compare->new()->perm( $_[0], $_[1] ) || 0; }

Output:

The arrays are identical.


Comment on Re: Identical Arrays
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2015-07-28 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls