August 1999 | Return to the Perl Hardware Store | Slide #18 |
If $x and $y are references, you can compare them with ==:
$x == $y
is true if and only if $x and $y refer to the same thing.
You can use this to recognize a reference that you have seen before:
sub index_of_object { my ($obj, @o_list) = @_; my $i; for ($i=0; $i < @o_list; $i++) { return $i if $o_list[$i] == $obj; } return; }
Or use it as an optimization:
sub obj_eq { my ($a, $b) = @_; return 1 if $a == $b; deep_compare($a, $b); }
Next | Copyright © 1999 M-J. Dominus |