#!/usr/bin/perl -w use strict; sub Obit::new { my( $this, $ref )= @_; my $desc= "$ref"; $desc .= " (${$ref})" if UNIVERSAL::isa( $ref, "SCALAR" ); warn "$desc is born.\n"; return bless $ref, $this; } sub Obit::DESTROY { my $self= shift; my $desc= "$self"; $desc .= " (${$self})" if $self->isa("SCALAR"); warn "$desc has died.\n"; } sub newprint { my $x= Obit->new( \shift ); return sub { my $y= shift; print "${$x}, $y!\n"; }; } $|= 1; { my $h= Obit->new( newprint("Howdy") ); warn "About to destroy \$h.\n"; } warn "\$h is no more.\n"; { my $g= Obit->new( newprint("Greetings") ); warn "About to destroy \$g.\n"; } warn "\$g is no more.\n"; __END__ SCALAR(0x1bbefc0) (Howdy) is born. CODE(0x1bbf074) is born. About to destroy $h. Obit=CODE(0x1bbf074) has died. Obit=SCALAR(0x1bbefc0) (Howdy) has died. $h is no more. SCALAR(0x1bb50d4) (Greetings) is born. CODE(0x1bbf074) is born. About to destroy $g. Obit=CODE(0x1bbf074) has died. Obit=SCALAR(0x1bb50d4) (Greetings) has died. $g is no more.