http://www.perlmonks.org?node_id=669259


in reply to How to explicitly destroy an object so that all other references to it would become false?

1)
Many thanks!

2)
>do you have an example?

package XXX; my %already_created_objects; sub new { my ($class, $X) = @_; if (!$already_created_objects{$X}) { $already_created_objects{$X} = bless {somekey => $X} $class; } $already_created_objects{$X} }
somewhere inside the script
... $obj = new XXX($some_var_which_can_repeat); ... if ($some_conditions) { some_superundef $obj } ...

Scalar::Util::weaken can do what I would like, but, as I've understood, it is required to mark as "weak" every reference to the object? Indirection layer seems more handy, may be...