if (size(p,1) /= size(q,1)) then
b = false
else
b = all (p == q)
endif
This assumes one-dimensonal arrays a and b. The all intrinsic returns true if the array expression p == q contains only true elements, if all elements are equal.
import"slices"
b := slices.Equal(p, q)
slices.Equal is generic and type-safe at compile time.
b := (p.count = q.count);
if b then for i := 0 to p.count-1 do
if (p.items[i] <> q.items[i]) then
begin
b := false;
break;
end;
use v5.10.1;
no warnings 'experimental::smartmatch';
$b = @array1 ~~ @array2;
The smartmatch operator will recursively compare two arrays (lists actually) and return true if it finds the same element values in both. See the documentation for specifics.
Unfortunately, smartmatch remains experimental because of its byzantine complexity. For this application it's fine.
Uses the CPAN smart::match module to enable smart match operator |M|. Unlike perl's experimental smartmatch operator ~~, array arguments must be references (hence the backslashes).
This does a numeric comparison of two flat lists, with minimal error checking. Perl's dynamic typing means lists can contain arbitrary mixing and nesting of strings and numbers or lists or hashes; For that you should use a CPAN module like Data::Compare.
CPAN module Data:Compare imports function Compare which can deeply compare two perl structures (lists, hashes, arbitrarily mixed and nested). If they are the same, true is returned.