Skip to Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

Symbol

use Symbol "delete_package";
delete_package("Foo::Bar");
print "deleted\n" unless exists $Foo::{"Bar::"};

use Symbol "gensym";
$sym1 = getsym();       # Returns new, anonymous typeglob.
$sym2 = getsym();       # Yet another new, anonymous typeglob.

package Demo;
use Symbol "qualify";
$sym = qualify("x");              # "Demo::x"
$sym = qualify("x", "Foo");       # "Foo::x"
$sym = qualify("Bar::x");         # "Bar::x"
$sym = qualify("Bar::x", "Foo");  # "Bar::x"

use Symbol "qualify_to_ref";
sub pass_handle(*) {
    my $fh = qualify_to_ref(shift, caller);
    …
}
# Now you can call pass_handle with FH, "FH", *FH, or \*FH.

The Symbol module provides functions to help manipulate global names: typeglobs, format names, filehandles, package symbol tables, and anything else you might want to name via a symbol table. The delete_package function completely clears out a package's namespace (effectively anonymizing any extra references to the symbol table's referents, including references from precompiled code). The gensym function returns an anonymous typeglob each time it is called. (This function isn't used so much these days, now that undefined scalars autovivify into proper filehandles when used as arguments to open, pipe, socket, and the like).

The qualify function takes a name that may or may not be completely package-qualified, and returns a name that is. If it needs to prepend the package name, it will use the name specified via the second argument (or if omitted, your current package name). The qualify_to_ref function works ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata