Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Discover a package global's symbol name given a reference

by broquaint (Abbot)
on Sep 17, 2004 at 10:19 UTC ( #391737=note: print w/ replies, xml ) Need Help??


in reply to Discover a package global's symbol name given a reference

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


Comment on Re: Discover a package global's symbol name given a reference
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://391737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2015-07-03 16:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (54 votes), past polls