in reply to Re: Comparing arrays
in thread Comparing arrays
Use the code from the FAQ!
In particular, note this line:$are_equal = compare_arrays(\@frogs, \@toads); sub compare_arrays { my ($first, $second) = @_; local $^W = 0; # 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; }
So the routine returns automatically if the arrays aren't of equal size. In your algorithm, you compare the elements in the arrays even if they're of different sizes. In fact, you explicitly wrote this in using your max function! Why? If the arrays aren't the same size, how could they possibly be equal?return 0 unless @$first == @$second;
Also, look at the FreezeThaw examples in the FAQ.
|
|---|