Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 cooling their heels in the Monastery: (5)
As of 2024-04-23 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found