in reply to comparing array elements

If you only need to know if the two arrays are identical, you can cheat a little by using join and eq.

@a = qw[1 2 3 4 5]; @b = qw[1 2 3 4 5]; @c = qw[1 2 3 4 6]; print "a is equivalent to b" if join("\0", @a) eq join("\0", @b); a is equivalent to b print "a is equivalent to c" if join("\0", @a) eq join("\0", @c);

This requires that you data doesn't contain nulls, and it will consume a large amount ram (breifly) if the arrays are large.

However, if you need to know where and/or what the differences are, then there is no avoiding a loop.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!

Replies are listed 'Best First'.
Re: Re: comparing array elements
by rir (Vicar) on Nov 21, 2003 at 22:01 UTC
    Update: I missed the doesn't contain nulls caveat in the previous post. I have no point.