Not commenting on the larger task of what you're trying to do, the smaller task you're trying to do is clobbering
$_.
I'd rewrite that as:
sub selfcontrol {
my $self = shift;
defined $_ and
length $_ and
not (/REF/ or /SCALAR/ or /ARRAY/ or /HASH/ or /CODE/ or /GLOB/) a
+nd
return $_
for ref $self;
carp "diem";
}
But it's probably simpler to use
sub selfcontrol {
my $self = shift;
return $self if eval {$self->can("can")}; # Only objects can dance!
carp "diem";
}
-- Randal L. Schwartz, Perl hacker