$are_equal = compare_arrays(\@frogs, \@toads); sub compare_arrays { my ($first, $second) = @_; no warnings; # silence spurious -w undef complaints return 0 unless @$first == @$second; for (my $i = 0; $i < @$first; $i++) { return 0 if $first->[$i] ne $second->[$i]; } return 1; }
Note that compare_arrays returns as soon as it can determine the equality - immediately if the refs point at the same array. If not, it returns as soon as it finds the first difference.
Update: Misread it as $first == $second zigdon is correct
In reply to Re: Comparing arrays
by jsprat
in thread Comparing arrays
by hotshot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |