icon Top 9 categories map      RocketAware > Perl >

Typeglobs and Filehandles

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.



Home

Search Perl pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    

Typeglobs and Filehandles

Perl uses an internal type called a typeglob to hold an entire symbol table entry. The type prefix of a typeglob is a *, because it represents all types. This used to be the preferred way to pass arrays and hashes by reference into a function, but now that we have real references, this is seldom needed. It also used to be the preferred way to pass filehandles into a function, but now that we have the *foo{THING} notation it isn't often needed for that, either. It is still needed to pass new filehandles into functions (*HANDLE{IO} only works if HANDLE has already been used).

If you need to use a typeglob to save away a filehandle, do it this way:

    $fh = *STDOUT;

or perhaps as a real reference, like this:

    $fh = \*STDOUT;

This is also a way to create a local filehandle. For example:

    sub newopen {
        my $path = shift;
        local *FH;  # not my!
        open (FH, $path) || return undef;
        return *FH;
    }
    $fh = newopen('/etc/passwd');

Another way to create local filehandles is with IO::Handle and its ilk, see the bottom of open().

See the perlref manpage, the perlsub manpage, and Symbol Tables for more discussion on typeglobs.

Source: Perl data types
Copyright: Larry Wall, et al.
Next:

Previous: List value constructors



(Corrections, notes, and links courtesy of RocketAware.com)


[Overview Topics]

Up to: PERL




Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perldata/Typeglobs_and_Filehandles.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments