Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: So what is an array slice anyway?

by Aristotle (Chancellor)
on Aug 26, 2004 at 08:13 UTC ( [id://385933]=note: print w/replies, xml ) Need Help??


in reply to Re^2: So what is an array slice anyway?
in thread So what is an array slice anyway?

Here's an idiomatic way to test whether the contents of two arrays are equal — assuming the elements are numbers, anyway.

print "equal\n" if @array1 == @array2 and !grep $array1[ $_ ] != $array2[ $_ ], 0 .. $#array1;

In scalar context, grep evaluates to the number of elements it returned, so that condition says "if both arrays have the same length, and if no elements are found which are not equal".

Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found