in reply to Re: Dereferencing a reference to a typeglob? [Postfix Dereference Syntax]
in thread Dereferencing a reference to a typeglob?

++, but this doesn't solve the OP's problem of derefing a lexical, it acts the same way as a normal deref does (unless I'm missing something):

perl -E 'my $a=25; my $x=\*a; say $x->**; say $$x;' *main::a *main::a
  • Comment on Re^2: Dereferencing a reference to a typeglob? [Postfix Dereference Syntax]
  • Download Code

Replies are listed 'Best First'.
Re^3: Dereferencing a reference to a typeglob? [Postfix Dereference Syntax]
by LanX (Saint) on Oct 29, 2016 at 15:08 UTC
    > perl -E 'my $a=25; my $x=\*a; ... '

    This code doesn't do what you think it does.

    *a is always addressing the typeglob of the global symbol(s) named a , i.e. &a, $a, @a, %a the filehandle a and the format a .

    ( see here for how to use the clearer {SLOT} syntax.)

    Maybe this code example makes it clearer:

    DB<104> $a=42; my $a=666; my $ra=\*a; print $$$ra 42

    update

    Best think of the STASH (= Symbol Table Hash) as a Hash of Hashes, where the second level "hash" is a special structure called "glob" which always has exactly 6 fixed entries, which are either undef or a reference.

    Lexicals use a totally different mechanism in the so called "Pad" and can't be addressed with * because there is nothing like a "lexical glob" unifying all lexical symbols.

    If you use PadWalker to introspect pads you'll see that $x', '%x', '@x listed as separate top level symbols.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^3: Dereferencing a reference to a typeglob? [Postfix Dereference Syntax]
by kcott (Archbishop) on Oct 30, 2016 at 01:05 UTC