Symbol::Get(3pm)

πŸ“¦
version 0.12 Β· 5 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Symbol::Get β€” the manual page, but make it cute πŸ’–

okay so this is Symbol::Get(3pm), part of the User Contributed Perl Documentation bestie collection, and it's literally about reading Perl's symbol table programmatically. no cap. let's get into it πŸ’…


✨ NAME ✨

Symbol::Get β€” read Perl's symbol table programmatically πŸ¦‹


✨ SYNOPSIS ✨

okay so picture this, you got a package and you want to poke at its guts:

package Foo;

our $name = 'haha';
our @list = ( 1, 2, 3 );
our %hash = ( foo => 1, bar => 2 );

use constant my_const => 'haha';

use constant my_const_list => qw( a b c );

sub doit { ... }

my $name_sr = Symbol::Get::get('$Foo::name');    # \$name
my $list_ar = Symbol::Get::get('@Foo::list');    # \@list
my $hash_hr = Symbol::Get::get('%Foo::hash');    $ \%hash

#Defaults to __PACKAGE__ if none is given:
my $doit_cr = Symbol::Get::get('&doit');

#Constants:
my $const_val = Symbol::Get::copy_constant('Foo::my_const');
my @const_list = Symbol::Get::copy_constant('Foo::my_const_list');

#The below return the same results since get_names() defaults
#to the current package if none is given.
my @names = Symbol::Get::get_names('Foo');      # keys %Foo::
my @names = Symbol::Get::get_names();

and yeah, that's honestly the whole vibe. slay.


✨ DESCRIPTION ✨

so like, occasionally I (the author, not me, I'm just the messenger πŸ’€) need to reference a variable programmatically. and this module is literally the answer to that. it gives you an easy, syntactic-sugar-y, read-only interface to the symbol table. read-only!! it's giving librarian energy, not gremlin energy πŸ™ˆ

and honestly? the SYNOPSIS above covers usage pretty well. it's right there. it ate. πŸ‘‘


🌸 ABOUT PERL CONSTANTS 🌸

okay so this is the important part, bestie, listen up 🫢

previous versions of this module were out here endorsing constructions like:

my $const_sr = Symbol::Get::get('Foo::my_const');
my $const_ar = Symbol::Get::get('Foo::my_const_list');

…to read constants from the symbol table. and the way that this isn't reliable across Perl versions?? 😭 so don't do it. periodt. instead, use copy_constant(). that's the move. no cap. ✨

🚨 bestie warning: the old get()-on-a-constant thing is not reliable across Perl versions. this is not a drill. use copy_constant() and be free. πŸ’–

✨ SEE ALSO ✨

  • Symbol::Values β€” go look at this one too, iykyk πŸ’œ

✨ LICENSE ✨

this module is licensed under the MIT License. iconic, honestly. πŸŽ€


and that's the whole page!! perl v5.38.2, dated 2024-04-27 β€” so like, this manual page is a lil vintage but she's still serving πŸ’… thanks for reading bestie, go reference some variables, you got this πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from