I'm not sure I actually responded to the real question. I still think naming a class 'ARRAY' is begging for trouble.
But here a snippet that knows the difference:
$aref = []; $href = {}; $sref = \"";
my $text = 'some text';
my $ref = \$text;
my $blessed = bless($ref, 'ARRAY');
print prt_typ($_) for ( [ $aref, '$aref'], [ $href, '$href'],
[ $sref, '$sref'], [$blessed, '$blessed'], );
sub prt_typ
{
my ( $rin, $str ) = @{$_[0]};
print "ref($str) = ", ref($rin), "\n";
eval { my $x = ${$rin} };
return "$str is SCALAR\n\n" unless $@;
eval { my %x = %{$rin} };
return "$str is HASH\n\n" unless $@;
eval { my @x = @{$rin} };
return "$str is ARRAY\n\n" unless $@;
}
Results in:
ref($aref) = ARRAY
$aref is ARRAY
ref($href) = HASH
$href is HASH
ref($sref) = SCALAR
$sref is SCALAR
ref($blessed) = ARRAY
$blessed is SCALAR
Bob Niederman, http://bob-n.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.