http://qs1969.pair.com?node_id=507395

bpphillips has asked for the wisdom of the Perl Monks concerning the following question:

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