Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just a couple of notes as a I retrace my understanding of this behavior. Here's some relevant text from perlref, section "Making References":
*foo{THING} returns undef if that particular THING hasn’t been used yet, except in the case of scalars. *foo{SCALAR} returns a reference to an anonymous scalar if $foo hasn’t been used yet. This might change in a future release.
One consequence of this is that at the symbol-table level, the following two packages are indistinguishable:
{ package Foo; our $x = undef; our @x = qw( alpha beta gamma ); } { package Bar; our @x = qw( alpha beta gamma ); }
... which I may demonstrate with some code of my own, once I come up with something convincing that navigates the sea of casting and dereferencing that is the Perl symbol table. So while I think I appreciate what broquaint is trying to get across, I don't think the above post addresses the "spirit" of the OP. I would agree with the as-yet unmade statement that Devel::Symdump is doing its best, but the underlying data is ambiguous, and so are the values returned from the module.

Indeed, such is the nature of globs. Thanks, bpphillips, for starting this conversation.

Update: Here's a more concrete example, following the package definitions above:

use strict; use warnings; use Data::Dumper; warn "Perl version is '$]'\n"; { package Foo; our $x = undef; our @x = qw( alpha beta gamma ); } { package Bar; our @x = qw( alpha beta gamma ); } symdump('Foo','x'); symdump('Bar','x'); sub symdump { my ($pkg, $symbol) = @_; local(*SYM) = do { no strict 'refs'; ${*{"$pkg\::"}}{$symbol}; }; foreach my $slot (qw( SCALAR ARRAY HASH )) { warn Data::Dumper->Dump( [*SYM{$slot}], [ "\${ \*{\$$pkg\::{$s +ymbol}}{$slot} }" ] ); } } __END__ Perl version is '5.008005' ${ *{$Foo::{x}}{SCALAR} } = \undef; ${ *{$Foo::{x}}{ARRAY} } = [ 'alpha', 'beta', 'gamma' ]; ${ *{$Foo::{x}}{HASH} } = undef; ${ *{$Bar::{x}}{SCALAR} } = \undef; ${ *{$Bar::{x}}{ARRAY} } = [ 'alpha', 'beta', 'gamma' ]; ${ *{$Bar::{x}}{HASH} } = undef;

In reply to Re^2: Devel::Symdump and symbol table woes by trammell
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found