my @array = (1, 2, 3);
my $aref = \@array;
showarray($aref);
my $text = 'some text';
my $ref = \$text;
my $blessed = bless($ref, 'ARRAY'); # bless the scalar reference into class ARRAY
showarray($blessed);
sub showarray {
my $aref = shift;
local $\ = $/; # set the output record seperator
return if (!UNIVERSAL::isa($aref, 'ARRAY'));
print ref($aref), ": @$aref";
}
__DATA__
ARRAY: 1 2 3
Not an ARRAY reference at reftype.pl line 14.
####
use B;
sub refcheck {
my $ref = shift;
return ref(B::svref_2object($ref)) =~ /B::(\w+)/;
}
####
sub reftype {
my $ref = shift;
$ref =~ s/\(.*\)$//; # get rid of the (0x0000000) portion of the reference
$ref =~ s/^.*=//; # get rid of the CLASS= portion of the reference
return $ref;
}