First, $hash{"b"} = qw/abc/; will store 'c' in $hash{"b"} , not an array, maybe you mean $hash{"b"} = [ qw/abc/ ]; , which will store the array reference in $hash{"b"} . This is a key bit of information. Everything except the scalar should be stored as a link when assigned to the scalar. There is a function called ref that will tell you the link information, but it will give you the class name of the object if the link was blessed. Fortunately, there is another function called reftype that always returns the structure type in Scalar::Util .
#!/usr/bin/perl use strict; use warnings; use Scalar::Util qw/reftype/; my $rs = \4; my $ra = [1 .. 5]; my $rh = { a => 1 }; my $obj = bless {}, "UNIVERSAL"; print "ref: ", ref($rs), " reftype: ", reftype($rs), "\n", "ref: ", ref($ra), " reftype: ", reftype($ra), "\n", "ref: ", ref($rh), " reftype: ", reftype($rh), "\n", "ref: ", ref($obj), " reftype: ", reftype($obj), "\n";
Chas. Owens
source share