Hello all,
Can somone explain why the following code has the indicated output?
package private; our $my_scalar = 'my scalar'; our @my_array = qw(my array); our %my_hash = ( my => 'hash' ); package main; use strict; use Devel::Symdump; print "ARRAYS => " . join(q{, }, Devel::Symdump->arrays("private")),"\n"; print "SCALARS => " . join(q{, }, Devel::Symdump->scalars("private")),"\n"; print "HASHES => " . join(q{, }, Devel::Symdump->hashes("private")),"\n"; # yields the following __END__ ARRAYS => private::my_array SCALARS => private::my_scalar, private::my_array, private::my_hash HASHES => private::my_hash
Devel::Symdump aside, what I really want to know is why the SCALAR entry for any non-scalar symbol table glob return a reference to undef instead of simply undef:
package private; our $my_scalar = 'my scalar'; our @my_array = qw(my array); package main; use strict; use Data::Dumper; # attempt to access the ARRAY portion of a scalar *my_scalar_glob = $private::{my_scalar}; print "ARRAY portion of a scalar glob: " . Dumper(*my_scalar_glob{ARRAY}); # attempt to access the SCALAR portion of an array *my_array_glob = $private::{my_array}; print "SCALAR portion of an array glob: " . Dumper(*my_array_glob{SCALAR}); __END__ # prints the following ARRAY portion of a scalar glob: $VAR1 = undef; SCALAR portion of an array glob: $VAR1 = \undef;
Devel::Symdump checks defined-ness in determining whether a symbol of a certain type exists and since the SCALAR portion of an ARRAY symbol table entry returns \undef, it passes that test and assumes that $private::my_array really exists as a scalar.

This seems at least unexpected and possibly a flaw at some level but I'm way over my head as far as my knowledge of Perl innards.

I look forward to being enlightened!

-- Brian

In reply to Devel::Symdump and symbol table woes by bpphillips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.