in reply to Comparing arrays
$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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(z) Re^2: Comparing arrays
by zigdon (Deacon) on Dec 24, 2002 at 13:16 UTC |