Perl Tutorials - Herong's Tutorial Examples - Version 5.32, by Dr. Herong Yang
Typeglob, Symbolic Table and Identifier Aliases
This section describes symbol table and, typeglob and identifier aliases. The symbol table is a hash used by the compiler to store all identifiers used in the package.
Typeglob: A special data type used by Perl compiler for the symbol table.
Symbol Table: A hash used by Perl compiler for each name space (package). The name of the symbol table hash is actually the package name followed with a double-colon, ::.
Keys in the symbol table are identifiers used in the name space. Values associated with keys are typeglobs.
There are two ways to access typeglobs:
Since the same identifier can be used for different data types, there will be only one entry in the symbol table for many variables of different data types, if they have the sample identifier.
One common usage of typeglobs is to create identifier aliases. There are several ways to create aliases:
1. Assigning one typeglob to another with "*" notations to create an alias for all data types. For example, "*main::foo = *main::bar" - "foo" is an alias for "bar" for all data types.
2. Assigning one typeglob to another with hash notations to create an alias for all data types. For example, "$main::{foo} = $main::{bar}" - "foo" is an alias for "bar" for all data types.
3. Assigning a hard reference to a typeglob to create an alias for one data type. For example "*main::foo = \$main::bar" - "foo" is an alias for "bar" for scalar varialbe.
Aliases can be used in the same place as the original identifier.
Here is a program to show you how to create and use identifier aliases:
#- TypeglobTest.pl #- Copyright (c) 1999 by Dr. Herong Yang, http://www.herongyang.com/ # &printHash("main::"); $x = 3.14; %x = (k1,9,k2,99,k3,999,k4,999); *y = *x; $a = "hello"; @a = (apple,banana,orange); *b = \$a; print "\$y = $y\n"; print "\$y{k3} = $y{k3}\n"; print "\$b = $b\n"; print "\$b[1] = $b[1]\n"; exit; sub printHash { local ($hashName) = @_; foreach $key (sort keys %$hashName) { print "$key = $$hashName{$key}\n"; } }
Here is the output with ActivePerl:
= *main:: ? = *main::? ? = *main::? " = *main::" $ = *main::$ / = *main::/ 0 = *main::0 @ = *main::@ ARGV = *main::ARGV CORE:: = *main::CORE:: DB:: = *main::DB:: DynaLoader:: = *main::DynaLoader:: ENV = *main::ENV INC = *main::INC IO:: = *main::IO:: STDERR = *main::STDERR STDIN = *main::STDIN STDOUT = *main::STDOUT UNIVERSAL:: = *main::UNIVERSAL:: Win32:: = *main::Win32:: a = *main::a attributes:: = *main::attributes:: b = *main::b hashName = *main::hashName key = *main::key main:: = *main::main:: printHash = *main::printHash stderr = *main::stderr stdin = *main::stdin stdout = *main::stdout x = *main::x y = *main::y $y = 3.14 $y{k3} = 999 $b = hello $b[1] =
Couple of interesting notes:
Table of Contents
Data Types: Values and Variables
Expressions, Operations and Simple Statements
Name Spaces and Perl Module Files
Hard References - Addresses of Memory Objects
Objects (or References) and Classes (or Packages)
►Typeglob and Importing Identifiers from Other Packages
►Typeglob, Symbolic Table and Identifier Aliases
Accessing Identifiers from Other Packages as Aliases
Exporting and Importing Package Identifiers
String Built-in Functions and Performance
File Handles and Data Input/Output
Open Directories and Read File Names
File System Functions and Operations
Converting Perl Script to Executable Binary
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
SOAP::Lite - SOAP Server-Client Communication Module
Perl Programs as IIS Server CGI Scripts
CGI (Common Gateway Interface)
XML-RPC - Remote Procedure Call with XML and HTTP
RPC::XML - Perl Implementation of XML-RPC
Integrating Perl with Apache Web Server
CGI.pm Module for Building Web Pages