Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Symbol::Get(3)	      User Contributed Perl Documentation	Symbol::Get(3)

NAME
       Symbol::Get - Read Perlas symbol	table programmatically

SYNOPSIS
	   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();

DESCRIPTION
       Occasionally I have need	to reference a variable	programmatically.
       This module facilitates that by providing an easy, syntactic-sugar-y,
       read-only interface to the symbol table.

       The SYNOPSIS above should pretty	well cover usage.

ABOUT PERL CONSTANTS
       Previous	versions of this module	endorsed constructions like:

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

       a| to read constants from the symbol table. This	isnat reliable across
       Perl versions, though, so donat do it; instead, use "copy_constant()".

SEE ALSO
       o   Symbol::Values

LICENSE
       This module is licensed under the same license as Perl.

perl v5.32.0			  2017-09-21			Symbol::Get(3)

NAME | SYNOPSIS | DESCRIPTION | ABOUT PERL CONSTANTS | SEE ALSO | LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Symbol::Get&sektion=3&manpath=FreeBSD+12.2-RELEASE+and+Ports>

home | help