Other Perl Globals


 
Network Programming with Perl
By Lincoln  D.  Stein
Slots : 1
Table of Contents
Appendix B.   Perl Error Codes and Special Variables

    Content

Magic Variables Affecting I/O

Perl has numerous global variables, many of which affect I/O in one way or another. Each variable is available as a cryptic "punctuation global" and, after loading the English module, optionally as a more friendly English-language variable. Many, but not all, of these variables are also available as IO::Handle class method calls.

For example, the variable $, , which contains the character to print between elements of a list, is available as $OUTPUT_FIELD_SEPARATOR when the English module is loaded, and as the output_field_separator() method when using IO::Handle. The following code fragment illustrates the equivalence relationships:

 use IO::Handle; use English; $, = `:';  # print ":" between members of a list $OUTPUT_FIELD_SEPARATOR = `:';            # same IO::Handle->output_field_separator(`:');  # same 

When these globals are used as IO::Handle methods, some act as class methods and are global to all filehandles and IO::Handle objects. The output_field_separator() method is an example of a class method. Other methods are specific to individual filehandle objects and should be called as object methods. The input_line_number() method, which gives the number of the last line read from the filehandle, is an example of this:

 $lineno = $fh->input_line_number(); 

In Table B.2, the first column is the punctuation variable, the second column is its English equivalent, and the third indicates whether it is also available as an IO::Handle method() call. The value of the third column is "class" if the method should be invoked as a class method global to all IO::Handle objects, "object" if it is available on a per-filehandle basis, or "no" if the global is not available as a method.

See the perlformat POD documentation for an explanation of how to use Perl's built-in formatted report generator.

Table B.2. Global I/O Variables
Variable English Method Description
$_ $ARG no Default destination for <> operator and other I/O functions
$, $OUTPUT_FIELD_SEPARATOR class Character to print between members of a list (default: none)
$ $OUTPUT_AUTOFLUSH object If set to nonzero, causes a flush on the currently selected filehandle with each output operation. Use the autoflush() method with IO::Handle objects
$\ $OUTPUT_RECORD_SEPARATOR class Character to print at the end of every output line (default: none)
$/ $INPUT_RECORD_SEPARATOR class Character that delimits input lines (default: "\n")
$: $FORMAT_LINE_BREAK_CHARACTERS class A string containing a list of characters after which a string may be broken to fill continuation fields in a report format
$^L $FORMAT_FORMFEED class Character used by the report formatter to generate a new page
$. $INPUT_LINE_NUMBER object Current input line number for the last filehandle read using <> or getline()
$= $FORMAT_LINES_PER_PAGE object Number of lines that need to print before emitting a linefeed when using Perl's formatted report facility
$- $FORMAT_LINES_LEFT object The number of lines left on the page when generating formatted reports
$% $FORMAT_PAGE_NUMBER object Current page number when producing formatted reports
$~ $FORMAT_NAME object Name of the current report format
$^ $FORMAT_TOP_NAME object Name of the top-of-page format, printed at the top of each page when producing formatted reports
$# $OFMT no Output format for printed numbers

   
Top


Network Programming with Perl
Network Programming with Perl
ISBN: 0201615711
EAN: 2147483647
Year: 2000
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net