How do I determine if a variable contains a type glob

A variable never contains a type glob. It either is a typeglob by itself - in that case the the string following the sigil can be looked up in the package's symbol table - or it contains a reference to a part of a typeglob (a typeglob slot entry container). In the latter case the reference carried inside the variable is identical to the contents of a certain typeglobs slot entry inside the symbol table. A none-typeglob (not package) variable never contains or is a type glob, all it can do is sharing the typeglob's reference for a certain type. Consider:

#!/usr/bin/perl -l our $foo = "bar"; # foo is a package variable # hence *foo typglob exists print "typeglob *foo ", exists $main::{foo} ? "exists" : "doesn't exis +t"; print "typeglob *bar ", exists $main::{bar} ? "exists" : "doesn't exis +t"; print "foo typeglob: ", *foo; print "foo scalar slot ref: ",*{"main::foo"}{SCALAR}; my $bar = *foo; print "bar content: $bar"; my $baz = *{"main::foo"}{SCALAR}; print "baz content: $baz"; print $$baz; my $quux = \$foo; # reference to scalar slot of *foo print "quux is $quux";

Note how *{"main::foo"}{SCALAR} and $baz and $quux all share the same reference, despite being different variables. So, if you want to determine whether a variable contains part of a typeglob, iterate over the keys of the current packages symbol table, and for each symbol, iterate over the typeglobs reference entries, and if those are equal to the variable's content, it shares some part(s) of a typeglob's values. That's all you can get.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: How do I determine if a variable contains a type glob? by shmem
in thread How do I determine if a variable contains a type glob? by dpchrist

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.