The switch code hurt my eyes somewhat so I simplified the glob look up code while keeping within the bounds of those ever handy strictures
use strict; our %TYPES = qw/ SCALAR $ ARRAY @ HASH % CODE & GLOB * IO * /; sub get_ref_name { my $ref = shift; my @pkgs = split '::', scalar( shift || caller ); my $tbl = \%main::; $tbl = $tbl->{"$_\::"} for @pkgs; my @names; for my $n ( keys %$tbl ) { push @names, map [ $TYPES{$_}, $n ], grep $ref == *{ $tbl->{$n} }{$_}, keys %TYPES; push @names, [ $TYPES{GLOB}, $n ] if $ref == \$tbl->{$n}; } return map $_->[0].join('::', @pkgs, $_->[1]), @names; } our $foo; our @bar; our %baz; *quux = \$foo; print join(', ', get_ref_name($_)), "\n" for \( $foo, @bar, %baz ), \&get_ref_name; __output__ $main::quux, $main::foo @main::bar %main::baz *main::wurble &main::get_ref_name
And that whole method can probably be done away with some B style magic.
HTH

_________
broquaint


In reply to Re: Discover a package global's symbol name given a reference by broquaint
in thread Discover a package global's symbol name given a reference by davido

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.