Symbol...::Name(3pm)

πŸ“¦
version 0.05 Β· 7 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay so bestie, <rainbow>Symbol::Global::Name</rainbow> β€” it finds the name and type of a global variable. that's it, that's the whole job, and it does it flawlessly πŸ’…

this one lives in the manual as Symbol...::Name(3pm) iykyk (the name got squished, it happens, she's still iconic) πŸŽ€


✨ SYNOPSIS ✨

like, look how easy this is:

package My;
our $VERSION = '0.1';

use Symbol::Global::Name;
print Symbol::Global::Name->find( \$VERSION );

# prints '$My::VERSION'

literally three lines of setup and then boom, you got the name πŸ¦‹


🌸 DESCRIPTION 🌸

so what's the vibe? it goes and lookups symbol table to find an element by reference. that's the whole thing. you hand it a reference, it hands you back the name. no cap. πŸ’–


πŸ‘‘ METHODS πŸ‘‘

πŸ”₯ find πŸ”₯

Symbol::Global::Name->find( \$VERSION );
Symbol::Global::Name->find( \$VERSION, package => 'My::Package' );
Symbol::Global::Name->find( reference => \$VERSION );
Symbol::Global::Name->find( reference => \$VERSION, package => 'My::Package' );

okay so here's the tea β˜• β€” find takes a reference and an optional package name.

what it gives you back is the name of the referenced variable, as long as it's in the package or sub-package and it's a global variable. two conditions, bestie, both gotta pass 🫢

and the returned name comes prefixed with the type sigil, eg. '$', '@', '%', '&' or '*'. so it's not just the name, it's the whole glow-up with the sigil attached ✨

note that both call styles work β€” positional \$VERSION or the named reference => \$VERSION β€” and package => 'My::Package' is optional in both. you pick your fighter πŸ’…

πŸ’œ AUTHOR πŸ’œ

Ruslan Zakirov <ruz@bestpractical.com> β€” thank you for your service, king πŸ‘‘


πŸŽ€ LICENSE πŸŽ€

Under the same terms as perl itself. iconic behavior, honestly 🌈


okay that's the whole page bestie!! this was documented in perl v5.36.0, dated 2022-11-19, and the manual name is Symbol...::Name(3pm). go forth and find your globals πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from