Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man1 / perlvar.1
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PERLVAR 1"
132.TH PERLVAR 1 "2002-06-08" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134perlvar \- Perl predefined variables
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137.Sh "Predefined Names"
138.IX Subsection "Predefined Names"
139The following names have special meaning to Perl. Most
140punctuation names have reasonable mnemonics, or analogs in the
141shells. Nevertheless, if you wish to use long variable names,
142you need only say
143.PP
144.Vb 1
145\& use English;
146.Ve
147.PP
148at the top of your program. This aliases all the short names to the long
149names in the current package. Some even have medium names, generally
150borrowed from \fBawk\fR. In general, it's best to use the
151.PP
152.Vb 1
153\& use English '-no_match_vars';
154.Ve
155.PP
156invocation if you don't need \f(CW$PREMATCH\fR, \f(CW$MATCH\fR, or \f(CW$POSTMATCH\fR, as it avoids
157a certain performance hit with the use of regular expressions. See
158English.
159.PP
160Variables that depend on the currently selected filehandle may be set by
161calling an appropriate object method on the IO::Handle object, although
162this is less efficient than using the regular built-in variables. (Summary
163lines below for this contain the word \s-1HANDLE\s0.) First you must say
164.PP
165.Vb 1
166\& use IO::Handle;
167.Ve
168.PP
169after which you may use either
170.PP
171.Vb 1
172\& method HANDLE EXPR
173.Ve
174.PP
175or more safely,
176.PP
177.Vb 1
178\& HANDLE->method(EXPR)
179.Ve
180.PP
181Each method returns the old value of the IO::Handle attribute.
182The methods each take an optional \s-1EXPR\s0, which, if supplied, specifies the
183new value for the IO::Handle attribute in question. If not supplied,
184most methods do nothing to the current value\*(--except for
185\&\fIautoflush()\fR, which will assume a 1 for you, just to be different.
186.PP
187Because loading in the IO::Handle class is an expensive operation, you should
188learn how to use the regular built-in variables.
189.PP
190A few of these variables are considered \*(L"read\-only\*(R". This means that if
191you try to assign to this variable, either directly or indirectly through
192a reference, you'll raise a run-time exception.
193.PP
194You should be very careful when modifying the default values of most
195special variables described in this document. In most cases you want
196to localize these variables before changing them, since if you don't,
197the change may affect other modules which rely on the default values
198of the special variables that you have changed. This is one of the
199correct ways to read the whole file at once:
200.PP
201.Vb 4
202\& open my $fh, "foo" or die $!;
203\& local $/; # enable localized slurp mode
204\& my $content = <$fh>;
205\& close $fh;
206.Ve
207.PP
208But the following code is quite bad:
209.PP
210.Vb 4
211\& open my $fh, "foo" or die $!;
212\& undef $/; # enable slurp mode
213\& my $content = <$fh>;
214\& close $fh;
215.Ve
216.PP
217since some other module, may want to read data from some file in the
218default \*(L"line mode\*(R", so if the code we have just presented has been
219executed, the global value of \f(CW$/\fR is now changed for any other code
220running inside the same Perl interpreter.
221.PP
222Usually when a variable is localized you want to make sure that this
223change affects the shortest scope possible. So unless you are already
224inside some short \f(CW\*(C`{}\*(C'\fR block, you should create one yourself. For
225example:
226.PP
227.Vb 7
228\& my $content = '';
229\& open my $fh, "foo" or die $!;
230\& {
231\& local $/;
232\& $content = <$fh>;
233\& }
234\& close $fh;
235.Ve
236.PP
237Here is an example of how your own code can go broken:
238.PP
239.Vb 8
240\& for (1..5){
241\& nasty_break();
242\& print "$_ ";
243\& }
244\& sub nasty_break {
245\& $_ = 5;
246\& # do something with $_
247\& }
248.Ve
249.PP
250You probably expect this code to print:
251.PP
252.Vb 1
253\& 1 2 3 4 5
254.Ve
255.PP
256but instead you get:
257.PP
258.Vb 1
259\& 5 5 5 5 5
260.Ve
261.PP
262Why? Because \fInasty_break()\fR modifies \f(CW$_\fR without localizing it
263first. The fix is to add \fIlocal()\fR:
264.PP
265.Vb 1
266\& local $_ = 5;
267.Ve
268.PP
269It's easy to notice the problem in such a short example, but in more
270complicated code you are looking for trouble if you don't localize
271changes to the special variables.
272.PP
273The following list is ordered by scalar variables first, then the
274arrays, then the hashes.
275.IP "$ARG" 8
276.IX Item "$ARG"
277.PD 0
278.IP "$_" 8
279.IX Item "$_"
280.PD
281The default input and pattern-searching space. The following pairs are
282equivalent:
283.Sp
284.Vb 2
285\& while (<>) {...} # equivalent only in while!
286\& while (defined($_ = <>)) {...}
287.Ve
288.Sp
289.Vb 2
290\& /^Subject:/
291\& $_ =~ /^Subject:/
292.Ve
293.Sp
294.Vb 2
295\& tr/a-z/A-Z/
296\& $_ =~ tr/a-z/A-Z/
297.Ve
298.Sp
299.Vb 2
300\& chomp
301\& chomp($_)
302.Ve
303.Sp
304Here are the places where Perl will assume \f(CW$_\fR even if you
305don't use it:
306.RS 8
307.IP "\(bu" 3
308Various unary functions, including functions like \fIord()\fR and \fIint()\fR, as well
309as the all file tests (\f(CW\*(C`\-f\*(C'\fR, \f(CW\*(C`\-d\*(C'\fR) except for \f(CW\*(C`\-t\*(C'\fR, which defaults to
310\&\s-1STDIN\s0.
311.IP "\(bu" 3
312Various list functions like \fIprint()\fR and \fIunlink()\fR.
313.IP "\(bu" 3
314The pattern matching operations \f(CW\*(C`m//\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, and \f(CW\*(C`tr///\*(C'\fR when used
315without an \f(CW\*(C`=~\*(C'\fR operator.
316.IP "\(bu" 3
317The default iterator variable in a \f(CW\*(C`foreach\*(C'\fR loop if no other
318variable is supplied.
319.IP "\(bu" 3
320The implicit iterator variable in the \fIgrep()\fR and \fImap()\fR functions.
321.IP "\(bu" 3
322The default place to put an input record when a \f(CW\*(C`<FH>\*(C'\fR
323operation's result is tested by itself as the sole criterion of a \f(CW\*(C`while\*(C'\fR
324test. Outside a \f(CW\*(C`while\*(C'\fR test, this will not happen.
325.RE
326.RS 8
327.Sp
328(Mnemonic: underline is understood in certain operations.)
329.RE
330.IP "$a" 8
331.IX Item "$a"
332.PD 0
333.IP "$b" 8
334.IX Item "$b"
335.PD
336Special package variables when using \fIsort()\fR, see \*(L"sort\*(R" in perlfunc.
337Because of this specialness \f(CW$a\fR and \f(CW$b\fR don't need to be declared
338(using \fIlocal()\fR, use vars, or \fIour()\fR) even when using the strict
339vars pragma. Don't lexicalize them with \f(CW\*(C`my $a\*(C'\fR or \f(CW\*(C`my $b\*(C'\fR
340if you want to be able to use them in the \fIsort()\fR comparison block
341or function.
342.IP "$<\fIdigits\fR>" 8
343.IX Item "$<digits>"
344Contains the subpattern from the corresponding set of capturing
345parentheses from the last pattern match, not counting patterns
346matched in nested blocks that have been exited already. (Mnemonic:
347like \edigits.) These variables are all read-only and dynamically
348scoped to the current \s-1BLOCK\s0.
349.IP "$MATCH" 8
350.IX Item "$MATCH"
351.PD 0
352.IP "$&" 8
353.PD
354The string matched by the last successful pattern match (not counting
355any matches hidden within a \s-1BLOCK\s0 or \fIeval()\fR enclosed by the current
356\&\s-1BLOCK\s0). (Mnemonic: like & in some editors.) This variable is read-only
357and dynamically scoped to the current \s-1BLOCK\s0.
358.Sp
359The use of this variable anywhere in a program imposes a considerable
360performance penalty on all regular expression matches. See \*(L"\s-1BUGS\s0\*(R".
361.IP "$PREMATCH" 8
362.IX Item "$PREMATCH"
363.PD 0
364.IP "$`" 8
365.PD
366The string preceding whatever was matched by the last successful
367pattern match (not counting any matches hidden within a \s-1BLOCK\s0 or eval
368enclosed by the current \s-1BLOCK\s0). (Mnemonic: \f(CW\*(C``\*(C'\fR often precedes a quoted
369string.) This variable is read\-only.
370.Sp
371The use of this variable anywhere in a program imposes a considerable
372performance penalty on all regular expression matches. See \*(L"\s-1BUGS\s0\*(R".
373.IP "$POSTMATCH" 8
374.IX Item "$POSTMATCH"
375.PD 0
376.IP "$'" 8
377.PD
378The string following whatever was matched by the last successful
379pattern match (not counting any matches hidden within a \s-1BLOCK\s0 or \fIeval()\fR
380enclosed by the current \s-1BLOCK\s0). (Mnemonic: \f(CW\*(C`'\*(C'\fR often follows a quoted
381string.) Example:
382.Sp
383.Vb 3
384\& local $_ = 'abcdefghi';
385\& /def/;
386\& print "$`:$&:$'\en"; # prints abc:def:ghi
387.Ve
388.Sp
389This variable is read-only and dynamically scoped to the current \s-1BLOCK\s0.
390.Sp
391The use of this variable anywhere in a program imposes a considerable
392performance penalty on all regular expression matches. See \*(L"\s-1BUGS\s0\*(R".
393.IP "$LAST_PAREN_MATCH" 8
394.IX Item "$LAST_PAREN_MATCH"
395.PD 0
396.IP "$+" 8
397.PD
398The text matched by the last bracket of the last successful search pattern.
399This is useful if you don't know which one of a set of alternative patterns
400matched. For example:
401.Sp
402.Vb 1
403\& /Version: (.*)|Revision: (.*)/ && ($rev = $+);
404.Ve
405.Sp
406(Mnemonic: be positive and forward looking.)
407This variable is read-only and dynamically scoped to the current \s-1BLOCK\s0.
408.IP "$^N" 8
409.IX Item "$^N"
410The text matched by the used group most-recently closed (i.e. the group
411with the rightmost closing parenthesis) of the last successful search
412pattern. (Mnemonic: the (possibly) Nested parenthesis that most
413recently closed.)
414.Sp
415This is primarily used inside \f(CW\*(C`(?{...})\*(C'\fR blocks for examining text
416recently matched. For example, to effectively capture text to a variable
417(in addition to \f(CW$1\fR, \f(CW$2\fR, etc.), replace \f(CW\*(C`(...)\*(C'\fR with
418.Sp
419.Vb 1
420\& (?:(...)(?{ $var = $^N }))
421.Ve
422.Sp
423By setting and then using \f(CW$var\fR in this way relieves you from having to
424worry about exactly which numbered set of parentheses they are.
425.Sp
426This variable is dynamically scoped to the current \s-1BLOCK\s0.
427.IP "@LAST_MATCH_END" 8
428.IX Item "@LAST_MATCH_END"
429.PD 0
430.IP "@+" 8
431.PD
432This array holds the offsets of the ends of the last successful
433submatches in the currently active dynamic scope. \f(CW$+[0]\fR is
434the offset into the string of the end of the entire match. This
435is the same value as what the \f(CW\*(C`pos\*(C'\fR function returns when called
436on the variable that was matched against. The \fIn\fRth element
437of this array holds the offset of the \fIn\fRth submatch, so
438\&\f(CW$+[1]\fR is the offset past where \f(CW$1\fR ends, \f(CW$+[2]\fR the offset
439past where \f(CW$2\fR ends, and so on. You can use \f(CW$#+\fR to determine
440how many subgroups were in the last successful match. See the
441examples given for the \f(CW\*(C`@\-\*(C'\fR variable.
442.IP "$MULTILINE_MATCHING" 8
443.IX Item "$MULTILINE_MATCHING"
444.PD 0
445.IP "$*" 8
446.PD
447Set to a non-zero integer value to do multi-line matching within a
448string, 0 (or undefined) to tell Perl that it can assume that strings
449contain a single line, for the purpose of optimizing pattern matches.
450Pattern matches on strings containing multiple newlines can produce
451confusing results when \f(CW$*\fR is 0 or undefined. Default is undefined.
452(Mnemonic: * matches multiple things.) This variable influences the
453interpretation of only \f(CW\*(C`^\*(C'\fR and \f(CW\*(C`$\*(C'\fR. A literal newline can be searched
454for even when \f(CW\*(C`$* == 0\*(C'\fR.
455.Sp
456Use of \f(CW$*\fR is deprecated in modern Perl, supplanted by
457the \f(CW\*(C`/s\*(C'\fR and \f(CW\*(C`/m\*(C'\fR modifiers on pattern matching.
458.Sp
459Assigning a non-numerical value to \f(CW$*\fR triggers a warning (and makes
460\&\f(CW$*\fR act if \f(CW\*(C`$* == 0\*(C'\fR), while assigning a numerical value to \f(CW$*\fR
461makes that an implicit \f(CW\*(C`int\*(C'\fR is applied on the value.
462.IP "\s-1HANDLE\-\s0>input_line_number(\s-1EXPR\s0)" 8
463.IX Item "HANDLE->input_line_number(EXPR)"
464.PD 0
465.IP "$INPUT_LINE_NUMBER" 8
466.IX Item "$INPUT_LINE_NUMBER"
467.IP "$NR" 8
468.IX Item "$NR"
469.IP "$." 8
470.PD
471Current line number for the last filehandle accessed.
472.Sp
473Each filehandle in Perl counts the number of lines that have been read
474from it. (Depending on the value of \f(CW$/\fR, Perl's idea of what
475constitutes a line may not match yours.) When a line is read from a
476filehandle (via \fIreadline()\fR or \f(CW\*(C`<>\*(C'\fR), or when \fItell()\fR or \fIseek()\fR is
477called on it, \f(CW$.\fR becomes an alias to the line counter for that
478filehandle.
479.Sp
480You can adjust the counter by assigning to \f(CW$.\fR, but this will not
481actually move the seek pointer. \fILocalizing \f(CI$.\fI will not localize
482the filehandle's line count\fR. Instead, it will localize perl's notion
483of which filehandle \f(CW$.\fR is currently aliased to.
484.Sp
485\&\f(CW$.\fR is reset when the filehandle is closed, but \fBnot\fR when an open
486filehandle is reopened without an intervening \fIclose()\fR. For more
487details, see "I/O Operators" in perlop. Because \f(CW\*(C`<>\*(C'\fR never does
488an explicit close, line numbers increase across \s-1ARGV\s0 files (but see
489examples in \*(L"eof\*(R" in perlfunc).
490.Sp
491You can also use \f(CW\*(C`HANDLE\->input_line_number(EXPR)\*(C'\fR to access the
492line counter for a given filehandle without having to worry about
493which handle you last accessed.
494.Sp
495(Mnemonic: many programs use \*(L".\*(R" to mean the current line number.)
496.IP "IO::Handle\->input_record_separator(\s-1EXPR\s0)" 8
497.IX Item "IO::Handle->input_record_separator(EXPR)"
498.PD 0
499.IP "$INPUT_RECORD_SEPARATOR" 8
500.IX Item "$INPUT_RECORD_SEPARATOR"
501.IP "$RS" 8
502.IX Item "$RS"
503.IP "$/" 8
504.PD
505The input record separator, newline by default. This
506influences Perl's idea of what a \*(L"line\*(R" is. Works like \fBawk\fR's \s-1RS\s0
507variable, including treating empty lines as a terminator if set to
508the null string. (An empty line cannot contain any spaces
509or tabs.) You may set it to a multi-character string to match a
510multi-character terminator, or to \f(CW\*(C`undef\*(C'\fR to read through the end
511of file. Setting it to \f(CW"\en\en"\fR means something slightly
512different than setting to \f(CW""\fR, if the file contains consecutive
513empty lines. Setting to \f(CW""\fR will treat two or more consecutive
514empty lines as a single empty line. Setting to \f(CW"\en\en"\fR will
515blindly assume that the next input character belongs to the next
516paragraph, even if it's a newline. (Mnemonic: / delimits
517line boundaries when quoting poetry.)
518.Sp
519.Vb 3
520\& local $/; # enable "slurp" mode
521\& local $_ = <FH>; # whole file now here
522\& s/\en[ \et]+/ /g;
523.Ve
524.Sp
525Remember: the value of \f(CW$/\fR is a string, not a regex. \fBawk\fR has to be
526better for something. :\-)
527.Sp
528Setting \f(CW$/\fR to a reference to an integer, scalar containing an integer, or
529scalar that's convertible to an integer will attempt to read records
530instead of lines, with the maximum record size being the referenced
531integer. So this:
532.Sp
533.Vb 3
534\& local $/ = \e32768; # or \e"32768", or \e$var_containing_32768
535\& open my $fh, $myfile or die $!;
536\& local $_ = <$fh>;
537.Ve
538.Sp
539will read a record of no more than 32768 bytes from \s-1FILE\s0. If you're
540not reading from a record-oriented file (or your \s-1OS\s0 doesn't have
541record-oriented files), then you'll likely get a full chunk of data
542with every read. If a record is larger than the record size you've
543set, you'll get the record back in pieces.
544.Sp
545On \s-1VMS\s0, record reads are done with the equivalent of \f(CW\*(C`sysread\*(C'\fR,
546so it's best not to mix record and non-record reads on the same
547file. (This is unlikely to be a problem, because any file you'd
548want to read in record mode is probably unusable in line mode.)
549Non-VMS systems do normal I/O, so it's safe to mix record and
550non-record reads of a file.
551.Sp
552See also \*(L"Newlines\*(R" in perlport. Also see \f(CW$.\fR.
553.IP "\s-1HANDLE\-\s0>autoflush(\s-1EXPR\s0)" 8
554.IX Item "HANDLE->autoflush(EXPR)"
555.PD 0
556.IP "$OUTPUT_AUTOFLUSH" 8
557.IX Item "$OUTPUT_AUTOFLUSH"
558.IP "$|" 8
559.PD
560If set to nonzero, forces a flush right away and after every write
561or print on the currently selected output channel. Default is 0
562(regardless of whether the channel is really buffered by the
563system or not; \f(CW$|\fR tells you only whether you've asked Perl
564explicitly to flush after each write). \s-1STDOUT\s0 will
565typically be line buffered if output is to the terminal and block
566buffered otherwise. Setting this variable is useful primarily when
567you are outputting to a pipe or socket, such as when you are running
568a Perl program under \fBrsh\fR and want to see the output as it's
569happening. This has no effect on input buffering. See \*(L"getc\*(R" in perlfunc
570for that. (Mnemonic: when you want your pipes to be piping hot.)
571.IP "IO::Handle\->output_field_separator \s-1EXPR\s0" 8
572.IX Item "IO::Handle->output_field_separator EXPR"
573.PD 0
574.IP "$OUTPUT_FIELD_SEPARATOR" 8
575.IX Item "$OUTPUT_FIELD_SEPARATOR"
576.IP "$OFS" 8
577.IX Item "$OFS"
578.IP "$," 8
579.PD
580The output field separator for the print operator. Ordinarily the
581print operator simply prints out its arguments without further
582adornment. To get behavior more like \fBawk\fR, set this variable as
583you would set \fBawk\fR's \s-1OFS\s0 variable to specify what is printed
584between fields. (Mnemonic: what is printed when there is a \*(L",\*(R" in
585your print statement.)
586.IP "IO::Handle\->output_record_separator \s-1EXPR\s0" 8
587.IX Item "IO::Handle->output_record_separator EXPR"
588.PD 0
589.IP "$OUTPUT_RECORD_SEPARATOR" 8
590.IX Item "$OUTPUT_RECORD_SEPARATOR"
591.IP "$ORS" 8
592.IX Item "$ORS"
593.IP "$\e" 8
594.IX Item "$"
595.PD
596The output record separator for the print operator. Ordinarily the
597print operator simply prints out its arguments as is, with no
598trailing newline or other end-of-record string added. To get
599behavior more like \fBawk\fR, set this variable as you would set
600\&\fBawk\fR's \s-1ORS\s0 variable to specify what is printed at the end of the
601print. (Mnemonic: you set \f(CW\*(C`$\e\*(C'\fR instead of adding \*(L"\en\*(R" at the
602end of the print. Also, it's just like \f(CW$/\fR, but it's what you
603get \*(L"back\*(R" from Perl.)
604.IP "$LIST_SEPARATOR" 8
605.IX Item "$LIST_SEPARATOR"
606.PD 0
607.IP "$""" 8
608.PD
609This is like \f(CW$,\fR except that it applies to array and slice values
610interpolated into a double-quoted string (or similar interpreted
611string). Default is a space. (Mnemonic: obvious, I think.)
612.IP "$SUBSCRIPT_SEPARATOR" 8
613.IX Item "$SUBSCRIPT_SEPARATOR"
614.PD 0
615.IP "$SUBSEP" 8
616.IX Item "$SUBSEP"
617.IP "$;" 8
618.PD
619The subscript separator for multidimensional array emulation. If you
620refer to a hash element as
621.Sp
622.Vb 1
623\& $foo{$a,$b,$c}
624.Ve
625.Sp
626it really means
627.Sp
628.Vb 1
629\& $foo{join($;, $a, $b, $c)}
630.Ve
631.Sp
632But don't put
633.Sp
634.Vb 1
635\& @foo{$a,$b,$c} # a slice--note the @
636.Ve
637.Sp
638which means
639.Sp
640.Vb 1
641\& ($foo{$a},$foo{$b},$foo{$c})
642.Ve
643.Sp
644Default is \*(L"\e034\*(R", the same as \s-1SUBSEP\s0 in \fBawk\fR. If your
645keys contain binary data there might not be any safe value for \f(CW$;\fR.
646(Mnemonic: comma (the syntactic subscript separator) is a
647semi\-semicolon. Yeah, I know, it's pretty lame, but \f(CW$,\fR is already
648taken for something more important.)
649.Sp
650Consider using \*(L"real\*(R" multidimensional arrays as described
651in perllol.
652.IP "$OFMT" 8
653.IX Item "$OFMT"
654.PD 0
655.IP "$#" 8
656.PD
657The output format for printed numbers. This variable is a half-hearted
658attempt to emulate \fBawk\fR's \s-1OFMT\s0 variable. There are times, however,
659when \fBawk\fR and Perl have differing notions of what counts as
660numeric. The initial value is "%.\fIn\fRg", where \fIn\fR is the value
661of the macro \s-1DBL_DIG\s0 from your system's \fIfloat.h\fR. This is different from
662\&\fBawk\fR's default \s-1OFMT\s0 setting of \*(L"%.6g\*(R", so you need to set \f(CW$#\fR
663explicitly to get \fBawk\fR's value. (Mnemonic: # is the number sign.)
664.Sp
665Use of \f(CW$#\fR is deprecated.
666.IP "\s-1HANDLE\-\s0>format_page_number(\s-1EXPR\s0)" 8
667.IX Item "HANDLE->format_page_number(EXPR)"
668.PD 0
669.IP "$FORMAT_PAGE_NUMBER" 8
670.IX Item "$FORMAT_PAGE_NUMBER"
671.IP "$%" 8
672.PD
673The current page number of the currently selected output channel.
674Used with formats.
675(Mnemonic: % is page number in \fBnroff\fR.)
676.IP "\s-1HANDLE\-\s0>format_lines_per_page(\s-1EXPR\s0)" 8
677.IX Item "HANDLE->format_lines_per_page(EXPR)"
678.PD 0
679.IP "$FORMAT_LINES_PER_PAGE" 8
680.IX Item "$FORMAT_LINES_PER_PAGE"
681.IP "$=" 8
682.PD
683The current page length (printable lines) of the currently selected
684output channel. Default is 60.
685Used with formats.
686(Mnemonic: = has horizontal lines.)
687.IP "\s-1HANDLE\-\s0>format_lines_left(\s-1EXPR\s0)" 8
688.IX Item "HANDLE->format_lines_left(EXPR)"
689.PD 0
690.IP "$FORMAT_LINES_LEFT" 8
691.IX Item "$FORMAT_LINES_LEFT"
692.IP "$\-" 8
693.PD
694The number of lines left on the page of the currently selected output
695channel.
696Used with formats.
697(Mnemonic: lines_on_page \- lines_printed.)
698.IP "@LAST_MATCH_START" 8
699.IX Item "@LAST_MATCH_START"
700.PD 0
701.IP "@\-" 8
702.PD
703$\-[0] is the offset of the start of the last successful match.
704\&\f(CW\*(C`$\-[\*(C'\fR\fIn\fR\f(CW\*(C`]\*(C'\fR is the offset of the start of the substring matched by
705\&\fIn\fR\-th subpattern, or undef if the subpattern did not match.
706.Sp
707Thus after a match against \f(CW$_\fR, $& coincides with \f(CW\*(C`substr $_, $\-[0],
708$+[0] \- $\-[0]\*(C'\fR. Similarly, \f(CW\*(C`$\*(C'\fR\fIn\fR coincides with \f(CW\*(C`substr $_, $\-[\*(C'\fR\fIn\fR\f(CW\*(C`],
709$+[\*(C'\fR\fIn\fR\f(CW\*(C`] \- $\-[\*(C'\fR\fIn\fR\f(CW\*(C`]\*(C'\fR if \f(CW\*(C`$\-[\*(C'\fR\fIn\fR\f(CW\*(C`]\*(C'\fR is defined, and $+ coincides with
710\&\f(CW\*(C`substr $_, $\-[$#\-], $+[$#\-]\*(C'\fR. One can use \f(CW\*(C`$#\-\*(C'\fR to find the last
711matched subgroup in the last successful match. Contrast with
712\&\f(CW$#+\fR, the number of subgroups in the regular expression. Compare
713with \f(CW\*(C`@+\*(C'\fR.
714.Sp
715This array holds the offsets of the beginnings of the last
716successful submatches in the currently active dynamic scope.
717\&\f(CW\*(C`$\-[0]\*(C'\fR is the offset into the string of the beginning of the
718entire match. The \fIn\fRth element of this array holds the offset
719of the \fIn\fRth submatch, so \f(CW\*(C`$\-[1]\*(C'\fR is the offset where \f(CW$1\fR
720begins, \f(CW\*(C`$\-[2]\*(C'\fR the offset where \f(CW$2\fR begins, and so on.
721.Sp
722After a match against some variable \f(CW$var:\fR
723.RS 8
724.ie n .IP "$`\fR is the same as \f(CW""substr($var, 0, $\-[0])""" 5
725.el .IP "\f(CW$`\fR is the same as \f(CWsubstr($var, 0, $\-[0])\fR" 5
726.IX Item "$` is the same as substr($var, 0, $-[0])"
727.PD 0
728.ie n .IP "$&\fR is the same as \f(CW""substr($var, $\-[0], $+[0] \- $\-[0])""" 5
729.el .IP "\f(CW$&\fR is the same as \f(CWsubstr($var, $\-[0], $+[0] \- $\-[0])\fR" 5
730.IX Item "$& is the same as substr($var, $-[0], $+[0] - $-[0])"
731.ie n .IP "$'\fR is the same as \f(CW""substr($var, $+[0])""" 5
732.el .IP "\f(CW$'\fR is the same as \f(CWsubstr($var, $+[0])\fR" 5
733.IX Item "$' is the same as substr($var, $+[0])"
734.ie n .IP "$1\fR is the same as \f(CW""substr($var, $\-[1], $+[1] \- $\-[1])""" 5
735.el .IP "\f(CW$1\fR is the same as \f(CWsubstr($var, $\-[1], $+[1] \- $\-[1])\fR" 5
736.IX Item "$1 is the same as substr($var, $-[1], $+[1] - $-[1])"
737.ie n .IP "$2\fR is the same as \f(CW""substr($var, $\-[2], $+[2] \- $\-[2])""" 5
738.el .IP "\f(CW$2\fR is the same as \f(CWsubstr($var, $\-[2], $+[2] \- $\-[2])\fR" 5
739.IX Item "$2 is the same as substr($var, $-[2], $+[2] - $-[2])"
740.ie n .IP "$3\fR is the same as \f(CW""substr $var, $\-[3], $+[3] \- $\-[3])""" 5
741.el .IP "\f(CW$3\fR is the same as \f(CWsubstr $var, $\-[3], $+[3] \- $\-[3])\fR" 5
742.IX Item "$3 is the same as substr $var, $-[3], $+[3] - $-[3])"
743.RE
744.RS 8
745.RE
746.IP "\s-1HANDLE\-\s0>format_name(\s-1EXPR\s0)" 8
747.IX Item "HANDLE->format_name(EXPR)"
748.IP "$FORMAT_NAME" 8
749.IX Item "$FORMAT_NAME"
750.IP "$~" 8
751.PD
752The name of the current report format for the currently selected output
753channel. Default is the name of the filehandle. (Mnemonic: brother to
754\&\f(CW$^\fR.)
755.IP "\s-1HANDLE\-\s0>format_top_name(\s-1EXPR\s0)" 8
756.IX Item "HANDLE->format_top_name(EXPR)"
757.PD 0
758.IP "$FORMAT_TOP_NAME" 8
759.IX Item "$FORMAT_TOP_NAME"
760.IP "$^" 8
761.PD
762The name of the current top-of-page format for the currently selected
763output channel. Default is the name of the filehandle with _TOP
764appended. (Mnemonic: points to top of page.)
765.IP "IO::Handle\->format_line_break_characters \s-1EXPR\s0" 8
766.IX Item "IO::Handle->format_line_break_characters EXPR"
767.PD 0
768.IP "$FORMAT_LINE_BREAK_CHARACTERS" 8
769.IX Item "$FORMAT_LINE_BREAK_CHARACTERS"
770.IP "$:" 8
771.PD
772The current set of characters after which a string may be broken to
773fill continuation fields (starting with ^) in a format. Default is
774\&\*(L"\ \en\-\*(R", to break on whitespace or hyphens. (Mnemonic: a \*(L"colon\*(R" in
775poetry is a part of a line.)
776.IP "IO::Handle\->format_formfeed \s-1EXPR\s0" 8
777.IX Item "IO::Handle->format_formfeed EXPR"
778.PD 0
779.IP "$FORMAT_FORMFEED" 8
780.IX Item "$FORMAT_FORMFEED"
781.IP "$^L" 8
782.IX Item "$^L"
783.PD
784What formats output as a form feed. Default is \ef.
785.IP "$ACCUMULATOR" 8
786.IX Item "$ACCUMULATOR"
787.PD 0
788.IP "$^A" 8
789.IX Item "$^A"
790.PD
791The current value of the \fIwrite()\fR accumulator for \fIformat()\fR lines. A format
792contains \fIformline()\fR calls that put their result into \f(CW$^A\fR. After
793calling its format, \fIwrite()\fR prints out the contents of \f(CW$^A\fR and empties.
794So you never really see the contents of \f(CW$^A\fR unless you call
795\&\fIformline()\fR yourself and then look at it. See perlform and
796\&\*(L"\fIformline()\fR\*(R" in perlfunc.
797.IP "$CHILD_ERROR" 8
798.IX Item "$CHILD_ERROR"
799.PD 0
800.IP "$?" 8
801.PD
802The status returned by the last pipe close, backtick (\f(CW``\fR) command,
803successful call to \fIwait()\fR or \fIwaitpid()\fR, or from the \fIsystem()\fR
804operator. This is just the 16\-bit status word returned by the
805\&\fIwait()\fR system call (or else is made up to look like it). Thus, the
806exit value of the subprocess is really (\f(CW\*(C`$? >> 8\*(C'\fR), and
807\&\f(CW\*(C`$? & 127\*(C'\fR gives which signal, if any, the process died from, and
808\&\f(CW\*(C`$? & 128\*(C'\fR reports whether there was a core dump. (Mnemonic:
809similar to \fBsh\fR and \fBksh\fR.)
810.Sp
811Additionally, if the \f(CW\*(C`h_errno\*(C'\fR variable is supported in C, its value
812is returned via $? if any \f(CW\*(C`gethost*()\*(C'\fR function fails.
813.Sp
814If you have installed a signal handler for \f(CW\*(C`SIGCHLD\*(C'\fR, the
815value of \f(CW$?\fR will usually be wrong outside that handler.
816.Sp
817Inside an \f(CW\*(C`END\*(C'\fR subroutine \f(CW$?\fR contains the value that is going to be
818given to \f(CW\*(C`exit()\*(C'\fR. You can modify \f(CW$?\fR in an \f(CW\*(C`END\*(C'\fR subroutine to
819change the exit status of your program. For example:
820.Sp
821.Vb 3
822\& END {
823\& $? = 1 if $? == 255; # die would make it 255
824\& }
825.Ve
826.Sp
827Under \s-1VMS\s0, the pragma \f(CW\*(C`use vmsish 'status'\*(C'\fR makes \f(CW$?\fR reflect the
828actual \s-1VMS\s0 exit status, instead of the default emulation of \s-1POSIX\s0
829status; see \*(L"$?\*(R" in perlvms for details.
830.Sp
831Also see \*(L"Error Indicators\*(R".
832.IP "${^ENCODING}" 8
833.IX Item "${^ENCODING}"
834The \fIobject reference\fR to the Encode object that is used to convert
835the source code to Unicode. Thanks to this variable your perl script
836does not have to be written in \s-1UTF\-8\s0. Default is \fIundef\fR. The direct
837manipulation of this variable is highly discouraged. See encoding
838for more details.
839.IP "$OS_ERROR" 8
840.IX Item "$OS_ERROR"
841.PD 0
842.IP "$ERRNO" 8
843.IX Item "$ERRNO"
844.IP "$!" 8
845.PD
846If used numerically, yields the current value of the C \f(CW\*(C`errno\*(C'\fR
847variable, or in other words, if a system or library call fails, it
848sets this variable. This means that the value of \f(CW$!\fR is meaningful
849only \fIimmediately\fR after a \fBfailure\fR:
850.Sp
851.Vb 10
852\& if (open(FH, $filename)) {
853\& # Here $! is meaningless.
854\& ...
855\& } else {
856\& # ONLY here is $! meaningful.
857\& ...
858\& # Already here $! might be meaningless.
859\& }
860\& # Since here we might have either success or failure,
861\& # here $! is meaningless.
862.Ve
863.Sp
864In the above \fImeaningless\fR stands for anything: zero, non\-zero,
865\&\f(CW\*(C`undef\*(C'\fR. A successful system or library call does \fBnot\fR set
866the variable to zero.
867.Sp
868If used an a string, yields the corresponding system error string.
869You can assign a number to \f(CW$!\fR to set \fIerrno\fR if, for instance,
870you want \f(CW"$!"\fR to return the string for error \fIn\fR, or you want
871to set the exit value for the \fIdie()\fR operator. (Mnemonic: What just
872went bang?)
873.Sp
874Also see \*(L"Error Indicators\*(R".
875.IP "%!" 8
876Each element of \f(CW\*(C`%!\*(C'\fR has a true value only if \f(CW$!\fR is set to that
877value. For example, \f(CW$!{ENOENT}\fR is true if and only if the current
878value of \f(CW$!\fR is \f(CW\*(C`ENOENT\*(C'\fR; that is, if the most recent error was
879\&\*(L"No such file or directory\*(R" (or its moral equivalent: not all operating
880systems give that exact error, and certainly not all languages).
881To check if a particular key is meaningful on your system, use
882\&\f(CW\*(C`exists $!{the_key}\*(C'\fR; for a list of legal keys, use \f(CW\*(C`keys %!\*(C'\fR.
883See Errno for more information, and also see above for the
884validity of \f(CW$!\fR.
885.IP "$EXTENDED_OS_ERROR" 8
886.IX Item "$EXTENDED_OS_ERROR"
887.PD 0
888.IP "$^E" 8
889.IX Item "$^E"
890.PD
891Error information specific to the current operating system. At
892the moment, this differs from \f(CW$!\fR under only \s-1VMS\s0, \s-1OS/2\s0, and Win32
893(and for MacPerl). On all other platforms, \f(CW$^E\fR is always just
894the same as \f(CW$!\fR.
895.Sp
896Under \s-1VMS\s0, \f(CW$^E\fR provides the \s-1VMS\s0 status value from the last
897system error. This is more specific information about the last
898system error than that provided by \f(CW$!\fR. This is particularly
899important when \f(CW$!\fR is set to \fB\s-1EVMSERR\s0\fR.
900.Sp
901Under \s-1OS/2\s0, \f(CW$^E\fR is set to the error code of the last call to
902\&\s-1OS/2\s0 \s-1API\s0 either via \s-1CRT\s0, or directly from perl.
903.Sp
904Under Win32, \f(CW$^E\fR always returns the last error information
905reported by the Win32 call \f(CW\*(C`GetLastError()\*(C'\fR which describes
906the last error from within the Win32 \s-1API\s0. Most Win32\-specific
907code will report errors via \f(CW$^E\fR. \s-1ANSI\s0 C and Unix-like calls
908set \f(CW\*(C`errno\*(C'\fR and so most portable Perl code will report errors
909via \f(CW$!\fR.
910.Sp
911Caveats mentioned in the description of \f(CW$!\fR generally apply to
912\&\f(CW$^E\fR, also. (Mnemonic: Extra error explanation.)
913.Sp
914Also see \*(L"Error Indicators\*(R".
915.IP "$EVAL_ERROR" 8
916.IX Item "$EVAL_ERROR"
917.PD 0
918.IP "$@" 8
919.PD
920The Perl syntax error message from the last \fIeval()\fR operator.
921If $@ is the null string, the last \fIeval()\fR parsed and executed
922correctly (although the operations you invoked may have failed in the
923normal fashion). (Mnemonic: Where was the syntax error \*(L"at\*(R"?)
924.Sp
925Warning messages are not collected in this variable. You can,
926however, set up a routine to process warnings by setting \f(CW$SIG{_\|_WARN_\|_}\fR
927as described below.
928.Sp
929Also see \*(L"Error Indicators\*(R".
930.IP "$PROCESS_ID" 8
931.IX Item "$PROCESS_ID"
932.PD 0
933.IP "$PID" 8
934.IX Item "$PID"
935.IP "$$" 8
936.PD
937The process number of the Perl running this script. You should
938consider this variable read\-only, although it will be altered
939across \fIfork()\fR calls. (Mnemonic: same as shells.)
940.IP "$REAL_USER_ID" 8
941.IX Item "$REAL_USER_ID"
942.PD 0
943.IP "$UID" 8
944.IX Item "$UID"
945.IP "$<" 8
946.PD
947The real uid of this process. (Mnemonic: it's the uid you came \fIfrom\fR,
948if you're running setuid.) You can change both the real uid and
949the effective uid at the same time by using \fIPOSIX::setuid()\fR.
950.IP "$EFFECTIVE_USER_ID" 8
951.IX Item "$EFFECTIVE_USER_ID"
952.PD 0
953.IP "$EUID" 8
954.IX Item "$EUID"
955.IP "$>" 8
956.PD
957The effective uid of this process. Example:
958.Sp
959.Vb 2
960\& $< = $>; # set real to effective uid
961\& ($<,$>) = ($>,$<); # swap real and effective uid
962.Ve
963.Sp
964You can change both the effective uid and the real uid at the same
965time by using \fIPOSIX::setuid()\fR.
966.Sp
967(Mnemonic: it's the uid you went \fIto\fR, if you're running setuid.)
968\&\f(CW$<\fR and \f(CW$>\fR can be swapped only on machines
969supporting \fIsetreuid()\fR.
970.IP "$REAL_GROUP_ID" 8
971.IX Item "$REAL_GROUP_ID"
972.PD 0
973.IP "$GID" 8
974.IX Item "$GID"
975.IP "$(" 8
976.PD
977The real gid of this process. If you are on a machine that supports
978membership in multiple groups simultaneously, gives a space separated
979list of groups you are in. The first number is the one returned by
980\&\fIgetgid()\fR, and the subsequent ones by \fIgetgroups()\fR, one of which may be
981the same as the first number.
982.Sp
983However, a value assigned to \f(CW$(\fR must be a single number used to
984set the real gid. So the value given by \f(CW$(\fR should \fInot\fR be assigned
985back to \f(CW$(\fR without being forced numeric, such as by adding zero.
986.Sp
987You can change both the real gid and the effective gid at the same
988time by using \fIPOSIX::setgid()\fR.
989.Sp
990(Mnemonic: parentheses are used to \fIgroup\fR things. The real gid is the
991group you \fIleft\fR, if you're running setgid.)
992.IP "$EFFECTIVE_GROUP_ID" 8
993.IX Item "$EFFECTIVE_GROUP_ID"
994.PD 0
995.IP "$EGID" 8
996.IX Item "$EGID"
997.IP "$)" 8
998.PD
999The effective gid of this process. If you are on a machine that
1000supports membership in multiple groups simultaneously, gives a space
1001separated list of groups you are in. The first number is the one
1002returned by \fIgetegid()\fR, and the subsequent ones by \fIgetgroups()\fR, one of
1003which may be the same as the first number.
1004.Sp
1005Similarly, a value assigned to \f(CW$)\fR must also be a space-separated
1006list of numbers. The first number sets the effective gid, and
1007the rest (if any) are passed to \fIsetgroups()\fR. To get the effect of an
1008empty list for \fIsetgroups()\fR, just repeat the new effective gid; that is,
1009to force an effective gid of 5 and an effectively empty \fIsetgroups()\fR
1010list, say \f(CW\*(C` $) = "5 5" \*(C'\fR.
1011.Sp
1012You can change both the effective gid and the real gid at the same
1013time by using \fIPOSIX::setgid()\fR (use only a single numeric argument).
1014.Sp
1015(Mnemonic: parentheses are used to \fIgroup\fR things. The effective gid
1016is the group that's \fIright\fR for you, if you're running setgid.)
1017.Sp
1018\&\f(CW$<\fR, \f(CW$>\fR, \f(CW$(\fR and \f(CW$)\fR can be set only on
1019machines that support the corresponding \fIset[re][ug]\fIid()\fI\fR routine. \f(CW$(\fR
1020and \f(CW$)\fR can be swapped only on machines supporting \fIsetregid()\fR.
1021.IP "$PROGRAM_NAME" 8
1022.IX Item "$PROGRAM_NAME"
1023.PD 0
1024.IP "$0" 8
1025.IX Item "$0"
1026.PD
1027Contains the name of the program being executed. On some operating
1028systems assigning to \f(CW$0\fR modifies the argument area that the \fBps\fR
1029program sees. This is more useful as a way of indicating the current
1030program state than it is for hiding the program you're running.
1031(Mnemonic: same as \fBsh\fR and \fBksh\fR.)
1032.Sp
1033Note for \s-1BSD\s0 users: setting \f(CW$0\fR does not completely remove \*(L"perl\*(R"
1034from the \fIps\fR\|(1) output. For example, setting \f(CW$0\fR to \f(CW"foobar"\fR will
1035result in \f(CW"perl: foobar (perl)"\fR. This is an operating system
1036feature.
1037.IP "$[" 8
1038The index of the first element in an array, and of the first character
1039in a substring. Default is 0, but you could theoretically set it
1040to 1 to make Perl behave more like \fBawk\fR (or Fortran) when
1041subscripting and when evaluating the \fIindex()\fR and \fIsubstr()\fR functions.
1042(Mnemonic: [ begins subscripts.)
1043.Sp
1044As of release 5 of Perl, assignment to \f(CW$[\fR is treated as a compiler
1045directive, and cannot influence the behavior of any other file.
1046Its use is highly discouraged.
1047.IP "$]" 8
1048The version + patchlevel / 1000 of the Perl interpreter. This variable
1049can be used to determine whether the Perl interpreter executing a
1050script is in the right range of versions. (Mnemonic: Is this version
1051of perl in the right bracket?) Example:
1052.Sp
1053.Vb 1
1054\& warn "No checksumming!\en" if $] < 3.019;
1055.Ve
1056.Sp
1057See also the documentation of \f(CW\*(C`use VERSION\*(C'\fR and \f(CW\*(C`require VERSION\*(C'\fR
1058for a convenient way to fail if the running Perl interpreter is too old.
1059.Sp
1060The floating point representation can sometimes lead to inaccurate
1061numeric comparisons. See \f(CW$^V\fR for a more modern representation of
1062the Perl version that allows accurate string comparisons.
1063.IP "$COMPILING" 8
1064.IX Item "$COMPILING"
1065.PD 0
1066.IP "$^C" 8
1067.IX Item "$^C"
1068.PD
1069The current value of the flag associated with the \fB\-c\fR switch.
1070Mainly of use with \fB\-MO=...\fR to allow code to alter its behavior
1071when being compiled, such as for example to \s-1AUTOLOAD\s0 at compile
1072time rather than normal, deferred loading. See perlcc. Setting
1073\&\f(CW\*(C`$^C = 1\*(C'\fR is similar to calling \f(CW\*(C`B::minus_c\*(C'\fR.
1074.IP "$DEBUGGING" 8
1075.IX Item "$DEBUGGING"
1076.PD 0
1077.IP "$^D" 8
1078.IX Item "$^D"
1079.PD
1080The current value of the debugging flags. (Mnemonic: value of \fB\-D\fR
1081switch.)
1082.IP "$SYSTEM_FD_MAX" 8
1083.IX Item "$SYSTEM_FD_MAX"
1084.PD 0
1085.IP "$^F" 8
1086.IX Item "$^F"
1087.PD
1088The maximum system file descriptor, ordinarily 2. System file
1089descriptors are passed to \fIexec()\fRed processes, while higher file
1090descriptors are not. Also, during an \fIopen()\fR, system file descriptors are
1091preserved even if the \fIopen()\fR fails. (Ordinary file descriptors are
1092closed before the \fIopen()\fR is attempted.) The close-on-exec
1093status of a file descriptor will be decided according to the value of
1094\&\f(CW$^F\fR when the corresponding file, pipe, or socket was opened, not the
1095time of the \fIexec()\fR.
1096.IP "$^H" 8
1097.IX Item "$^H"
1098\&\s-1WARNING:\s0 This variable is strictly for internal use only. Its availability,
1099behavior, and contents are subject to change without notice.
1100.Sp
1101This variable contains compile-time hints for the Perl interpreter. At the
1102end of compilation of a \s-1BLOCK\s0 the value of this variable is restored to the
1103value when the interpreter started to compile the \s-1BLOCK\s0.
1104.Sp
1105When perl begins to parse any block construct that provides a lexical scope
1106(e.g., eval body, required file, subroutine body, loop body, or conditional
1107block), the existing value of $^H is saved, but its value is left unchanged.
1108When the compilation of the block is completed, it regains the saved value.
1109Between the points where its value is saved and restored, code that
1110executes within \s-1BEGIN\s0 blocks is free to change the value of $^H.
1111.Sp
1112This behavior provides the semantic of lexical scoping, and is used in,
1113for instance, the \f(CW\*(C`use strict\*(C'\fR pragma.
1114.Sp
1115The contents should be an integer; different bits of it are used for
1116different pragmatic flags. Here's an example:
1117.Sp
1118.Vb 1
1119\& sub add_100 { $^H |= 0x100 }
1120.Ve
1121.Sp
1122.Vb 4
1123\& sub foo {
1124\& BEGIN { add_100() }
1125\& bar->baz($boon);
1126\& }
1127.Ve
1128.Sp
1129Consider what happens during execution of the \s-1BEGIN\s0 block. At this point
1130the \s-1BEGIN\s0 block has already been compiled, but the body of \fIfoo()\fR is still
1131being compiled. The new value of $^H will therefore be visible only while
1132the body of \fIfoo()\fR is being compiled.
1133.Sp
1134Substitution of the above \s-1BEGIN\s0 block with:
1135.Sp
1136.Vb 1
1137\& BEGIN { require strict; strict->import('vars') }
1138.Ve
1139.Sp
1140demonstrates how \f(CW\*(C`use strict 'vars'\*(C'\fR is implemented. Here's a conditional
1141version of the same lexical pragma:
1142.Sp
1143.Vb 1
1144\& BEGIN { require strict; strict->import('vars') if $condition }
1145.Ve
1146.IP "%^H" 8
1147.IX Item "%^H"
1148\&\s-1WARNING:\s0 This variable is strictly for internal use only. Its availability,
1149behavior, and contents are subject to change without notice.
1150.Sp
1151The %^H hash provides the same scoping semantic as $^H. This makes it
1152useful for implementation of lexically scoped pragmas.
1153.IP "$INPLACE_EDIT" 8
1154.IX Item "$INPLACE_EDIT"
1155.PD 0
1156.IP "$^I" 8
1157.IX Item "$^I"
1158.PD
1159The current value of the inplace-edit extension. Use \f(CW\*(C`undef\*(C'\fR to disable
1160inplace editing. (Mnemonic: value of \fB\-i\fR switch.)
1161.IP "$^M" 8
1162.IX Item "$^M"
1163By default, running out of memory is an untrappable, fatal error.
1164However, if suitably built, Perl can use the contents of \f(CW$^M\fR
1165as an emergency memory pool after \fIdie()\fRing. Suppose that your Perl
1166were compiled with \-DPERL_EMERGENCY_SBRK and used Perl's malloc.
1167Then
1168.Sp
1169.Vb 1
1170\& $^M = 'a' x (1 << 16);
1171.Ve
1172.Sp
1173would allocate a 64K buffer for use in an emergency. See the
1174\&\fI\s-1INSTALL\s0\fR file in the Perl distribution for information on how to
1175enable this option. To discourage casual use of this advanced
1176feature, there is no English long name for this variable.
1177.IP "$OSNAME" 8
1178.IX Item "$OSNAME"
1179.PD 0
1180.IP "$^O" 8
1181.IX Item "$^O"
1182.PD
1183The name of the operating system under which this copy of Perl was
1184built, as determined during the configuration process. The value
1185is identical to \f(CW$Config{'osname'}\fR. See also Config and the
1186\&\fB\-V\fR command-line switch documented in perlrun.
1187.Sp
1188In Windows platforms, $^O is not very helpful: since it is always
1189\&\f(CW\*(C`MSWin32\*(C'\fR, it doesn't tell the difference between
119095/98/ME/NT/2000/XP/CE/.NET. Use \fIWin32::GetOSName()\fR or
1191\&\fIWin32::GetOSVersion()\fR (see Win32 and perlport) to distinguish
1192between the variants.
1193.IP "${^OPEN}" 8
1194.IX Item "${^OPEN}"
1195An internal variable used by PerlIO. A string in two parts, separated
1196by a \f(CW\*(C`\e0\*(C'\fR byte, the first part describes the input layers, the second
1197part describes the output layers.
1198.IP "$PERLDB" 8
1199.IX Item "$PERLDB"
1200.PD 0
1201.IP "$^P" 8
1202.IX Item "$^P"
1203.PD
1204The internal variable for debugging support. The meanings of the
1205various bits are subject to change, but currently indicate:
1206.RS 8
1207.IP "0x01" 6
1208.IX Item "0x01"
1209Debug subroutine enter/exit.
1210.IP "0x02" 6
1211.IX Item "0x02"
1212Line-by-line debugging.
1213.IP "0x04" 6
1214.IX Item "0x04"
1215Switch off optimizations.
1216.IP "0x08" 6
1217.IX Item "0x08"
1218Preserve more data for future interactive inspections.
1219.IP "0x10" 6
1220.IX Item "0x10"
1221Keep info about source lines on which a subroutine is defined.
1222.IP "0x20" 6
1223.IX Item "0x20"
1224Start with single-step on.
1225.IP "0x40" 6
1226.IX Item "0x40"
1227Use subroutine address instead of name when reporting.
1228.IP "0x80" 6
1229.IX Item "0x80"
1230Report \f(CW\*(C`goto &subroutine\*(C'\fR as well.
1231.IP "0x100" 6
1232.IX Item "0x100"
1233Provide informative \*(L"file\*(R" names for evals based on the place they were compiled.
1234.IP "0x200" 6
1235.IX Item "0x200"
1236Provide informative names to anonymous subroutines based on the place they
1237were compiled.
1238.RE
1239.RS 8
1240.Sp
1241Some bits may be relevant at compile-time only, some at
1242run-time only. This is a new mechanism and the details may change.
1243.RE
1244.IP "$LAST_REGEXP_CODE_RESULT" 8
1245.IX Item "$LAST_REGEXP_CODE_RESULT"
1246.PD 0
1247.IP "$^R" 8
1248.IX Item "$^R"
1249.PD
1250The result of evaluation of the last successful \f(CW\*(C`(?{ code })\*(C'\fR
1251regular expression assertion (see perlre). May be written to.
1252.IP "$EXCEPTIONS_BEING_CAUGHT" 8
1253.IX Item "$EXCEPTIONS_BEING_CAUGHT"
1254.PD 0
1255.IP "$^S" 8
1256.IX Item "$^S"
1257.PD
1258Current state of the interpreter. Undefined if parsing of the current
1259module/eval is not finished (may happen in \f(CW$SIG\fR{_\|_DIE_\|_} and
1260\&\f(CW$SIG\fR{_\|_WARN_\|_} handlers). True if inside an \fIeval()\fR, otherwise false.
1261.IP "$BASETIME" 8
1262.IX Item "$BASETIME"
1263.PD 0
1264.IP "$^T" 8
1265.IX Item "$^T"
1266.PD
1267The time at which the program began running, in seconds since the
1268epoch (beginning of 1970). The values returned by the \fB\-M\fR, \fB\-A\fR,
1269and \fB\-C\fR filetests are based on this value.
1270.IP "${^TAINT}" 8
1271.IX Item "${^TAINT}"
1272Reflects if taint mode is on or off (i.e. if the program was run with
1273\&\fB\-T\fR or not). True for on, false for off.
1274.IP "$PERL_VERSION" 8
1275.IX Item "$PERL_VERSION"
1276.PD 0
1277.IP "$^V" 8
1278.IX Item "$^V"
1279.PD
1280The revision, version, and subversion of the Perl interpreter, represented
1281as a string composed of characters with those ordinals. Thus in Perl v5.6.0
1282it equals \f(CW\*(C`chr(5) . chr(6) . chr(0)\*(C'\fR and will return true for
1283\&\f(CW\*(C`$^V eq v5.6.0\*(C'\fR. Note that the characters in this string value can
1284potentially be in Unicode range.
1285.Sp
1286This can be used to determine whether the Perl interpreter executing a
1287script is in the right range of versions. (Mnemonic: use ^V for Version
1288Control.) Example:
1289.Sp
1290.Vb 1
1291\& warn "No \e"our\e" declarations!\en" if $^V and $^V lt v5.6.0;
1292.Ve
1293.Sp
1294To convert \f(CW$^V\fR into its string representation use \fIsprintf()\fR's
1295\&\f(CW"%vd"\fR conversion:
1296.Sp
1297.Vb 1
1298\& printf "version is v%vd\en", $^V; # Perl's version
1299.Ve
1300.Sp
1301See the documentation of \f(CW\*(C`use VERSION\*(C'\fR and \f(CW\*(C`require VERSION\*(C'\fR
1302for a convenient way to fail if the running Perl interpreter is too old.
1303.Sp
1304See also \f(CW$]\fR for an older representation of the Perl version.
1305.IP "$WARNING" 8
1306.IX Item "$WARNING"
1307.PD 0
1308.IP "$^W" 8
1309.IX Item "$^W"
1310.PD
1311The current value of the warning switch, initially true if \fB\-w\fR
1312was used, false otherwise, but directly modifiable. (Mnemonic:
1313related to the \fB\-w\fR switch.) See also warnings.
1314.IP "${^WARNING_BITS}" 8
1315.IX Item "${^WARNING_BITS}"
1316The current set of warning checks enabled by the \f(CW\*(C`use warnings\*(C'\fR pragma.
1317See the documentation of \f(CW\*(C`warnings\*(C'\fR for more details.
1318.IP "${^WIDE_SYSTEM_CALLS}" 8
1319.IX Item "${^WIDE_SYSTEM_CALLS}"
1320Global flag that enables system calls made by Perl to use wide character
1321APIs native to the system, if available. This is currently only implemented
1322on the Windows platform.
1323.Sp
1324This can also be enabled from the command line using the \f(CW\*(C`\-C\*(C'\fR switch.
1325.Sp
1326The initial value is typically \f(CW0\fR for compatibility with Perl versions
1327earlier than 5.6, but may be automatically set to \f(CW1\fR by Perl if the system
1328provides a user-settable default (e.g., \f(CW$ENV{LC_CTYPE}\fR).
1329.Sp
1330The \f(CW\*(C`bytes\*(C'\fR pragma always overrides the effect of this flag in the current
1331lexical scope. See bytes.
1332.IP "$EXECUTABLE_NAME" 8
1333.IX Item "$EXECUTABLE_NAME"
1334.PD 0
1335.IP "$^X" 8
1336.IX Item "$^X"
1337.PD
1338The name used to execute the current copy of Perl, from C's
1339\&\f(CW\*(C`argv[0]\*(C'\fR.
1340.Sp
1341Depending on the host operating system, the value of $^X may be
1342a relative or absolute pathname of the perl program file, or may
1343be the string used to invoke perl but not the pathname of the
1344perl program file. Also, most operating systems permit invoking
1345programs that are not in the \s-1PATH\s0 environment variable, so there
1346is no guarantee that the value of $^X is in \s-1PATH\s0. For \s-1VMS\s0, the
1347value may or may not include a version number.
1348.Sp
1349You usually can use the value of $^X to re-invoke an independent
1350copy of the same perl that is currently running, e.g.,
1351.Sp
1352.Vb 1
1353\& @first_run = `$^X -le "print int rand 100 for 1..100"`;
1354.Ve
1355.Sp
1356But recall that not all operating systems support forking or
1357capturing of the output of commands, so this complex statement
1358may not be portable.
1359.Sp
1360It is not safe to use the value of $^X as a path name of a file,
1361as some operating systems that have a mandatory suffix on
1362executable files do not require use of the suffix when invoking
1363a command. To convert the value of $^X to a path name, use the
1364following statements:
1365.Sp
1366# Build up a set of file names (not command names).
1367 use Config;
1368 \f(CW$this_perl\fR = $^X;
1369 if ($^O ne '\s-1VMS\s0')
1370 {$this_perl .= \f(CW$Config\fR{_exe}
1371 unless \f(CW$this_perl\fR =~ m/$Config{_exe}$/i;}
1372.Sp
1373Because many operating systems permit anyone with read access to
1374the Perl program file to make a copy of it, patch the copy, and
1375then execute the copy, the security-conscious Perl programmer
1376should take care to invoke the installed copy of perl, not the
1377copy referenced by $^X. The following statements accomplish
1378this goal, and produce a pathname that can be invoked as a
1379command or referenced as a file.
1380.Sp
1381.Vb 5
1382\& use Config;
1383\& $secure_perl_path = $Config{perlpath};
1384\& if ($^O ne 'VMS')
1385\& {$secure_perl_path .= $Config{_exe}
1386\& unless $secure_perl_path =~ m/$Config{_exe}$/i;}
1387.Ve
1388.IP "\s-1ARGV\s0" 8
1389.IX Item "ARGV"
1390The special filehandle that iterates over command-line filenames in
1391\&\f(CW@ARGV\fR. Usually written as the null filehandle in the angle operator
1392\&\f(CW\*(C`<>\*(C'\fR. Note that currently \f(CW\*(C`ARGV\*(C'\fR only has its magical effect
1393within the \f(CW\*(C`<>\*(C'\fR operator; elsewhere it is just a plain filehandle
1394corresponding to the last file opened by \f(CW\*(C`<>\*(C'\fR. In particular,
1395passing \f(CW\*(C`\e*ARGV\*(C'\fR as a parameter to a function that expects a filehandle
1396may not cause your function to automatically read the contents of all the
1397files in \f(CW@ARGV\fR.
1398.IP "$ARGV" 8
1399.IX Item "$ARGV"
1400contains the name of the current file when reading from <>.
1401.IP "@ARGV" 8
1402.IX Item "@ARGV"
1403The array \f(CW@ARGV\fR contains the command-line arguments intended for
1404the script. \f(CW$#ARGV\fR is generally the number of arguments minus
1405one, because \f(CW$ARGV[0]\fR is the first argument, \fInot\fR the program's
1406command name itself. See \f(CW$0\fR for the command name.
1407.IP "\s-1ARGVOUT\s0" 8
1408.IX Item "ARGVOUT"
1409The special filehandle that points to the currently open output file
1410when doing edit-in-place processing with \fB\-i\fR. Useful when you have
1411to do a lot of inserting and don't want to keep modifying \f(CW$_\fR. See
1412perlrun for the \fB\-i\fR switch.
1413.IP "@F" 8
1414.IX Item "@F"
1415The array \f(CW@F\fR contains the fields of each line read in when autosplit
1416mode is turned on. See perlrun for the \fB\-a\fR switch. This array
1417is package\-specific, and must be declared or given a full package name
1418if not in package main when running under \f(CW\*(C`strict 'vars'\*(C'\fR.
1419.IP "@INC" 8
1420.IX Item "@INC"
1421The array \f(CW@INC\fR contains the list of places that the \f(CW\*(C`do EXPR\*(C'\fR,
1422\&\f(CW\*(C`require\*(C'\fR, or \f(CW\*(C`use\*(C'\fR constructs look for their library files. It
1423initially consists of the arguments to any \fB\-I\fR command-line
1424switches, followed by the default Perl library, probably
1425\&\fI/usr/local/lib/perl\fR, followed by \*(L".\*(R", to represent the current
1426directory. (\*(L".\*(R" will not be appended if taint checks are enabled, either by
1427\&\f(CW\*(C`\-T\*(C'\fR or by \f(CW\*(C`\-t\*(C'\fR.) If you need to modify this at runtime, you should use
1428the \f(CW\*(C`use lib\*(C'\fR pragma to get the machine-dependent library properly
1429loaded also:
1430.Sp
1431.Vb 2
1432\& use lib '/mypath/libdir/';
1433\& use SomeMod;
1434.Ve
1435.Sp
1436You can also insert hooks into the file inclusion system by putting Perl
1437code directly into \f(CW@INC\fR. Those hooks may be subroutine references, array
1438references or blessed objects. See \*(L"require\*(R" in perlfunc for details.
1439.IP "@_" 8
1440.IX Item "@_"
1441Within a subroutine the array \f(CW@_\fR contains the parameters passed to that
1442subroutine. See perlsub.
1443.IP "%INC" 8
1444.IX Item "%INC"
1445The hash \f(CW%INC\fR contains entries for each filename included via the
1446\&\f(CW\*(C`do\*(C'\fR, \f(CW\*(C`require\*(C'\fR, or \f(CW\*(C`use\*(C'\fR operators. The key is the filename
1447you specified (with module names converted to pathnames), and the
1448value is the location of the file found. The \f(CW\*(C`require\*(C'\fR
1449operator uses this hash to determine whether a particular file has
1450already been included.
1451.Sp
1452If the file was loaded via a hook (e.g. a subroutine reference, see
1453\&\*(L"require\*(R" in perlfunc for a description of these hooks), this hook is
1454by default inserted into \f(CW%INC\fR in place of a filename. Note, however,
1455that the hook may have set the \f(CW%INC\fR entry by itself to provide some more
1456specific info.
1457.IP "%ENV" 8
1458.IX Item "%ENV"
1459.PD 0
1460.IP "$ENV{expr}" 8
1461.IX Item "$ENV{expr}"
1462.PD
1463The hash \f(CW%ENV\fR contains your current environment. Setting a
1464value in \f(CW\*(C`ENV\*(C'\fR changes the environment for any child processes
1465you subsequently \fIfork()\fR off.
1466.IP "%SIG" 8
1467.IX Item "%SIG"
1468.PD 0
1469.IP "$SIG{expr}" 8
1470.IX Item "$SIG{expr}"
1471.PD
1472The hash \f(CW%SIG\fR contains signal handlers for signals. For example:
1473.Sp
1474.Vb 6
1475\& sub handler { # 1st argument is signal name
1476\& my($sig) = @_;
1477\& print "Caught a SIG$sig--shutting down\en";
1478\& close(LOG);
1479\& exit(0);
1480\& }
1481.Ve
1482.Sp
1483.Vb 5
1484\& $SIG{'INT'} = \e&handler;
1485\& $SIG{'QUIT'} = \e&handler;
1486\& ...
1487\& $SIG{'INT'} = 'DEFAULT'; # restore default action
1488\& $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT
1489.Ve
1490.Sp
1491Using a value of \f(CW'IGNORE'\fR usually has the effect of ignoring the
1492signal, except for the \f(CW\*(C`CHLD\*(C'\fR signal. See perlipc for more about
1493this special case.
1494.Sp
1495Here are some other examples:
1496.Sp
1497.Vb 4
1498\& $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not recommended)
1499\& $SIG{"PIPE"} = \e&Plumber; # just fine; assume current Plumber
1500\& $SIG{"PIPE"} = *Plumber; # somewhat esoteric
1501\& $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() return??
1502.Ve
1503.Sp
1504Be sure not to use a bareword as the name of a signal handler,
1505lest you inadvertently call it.
1506.Sp
1507If your system has the \fIsigaction()\fR function then signal handlers are
1508installed using it. This means you get reliable signal handling. If
1509your system has the \s-1SA_RESTART\s0 flag it is used when signals handlers are
1510installed. This means that system calls for which restarting is supported
1511continue rather than returning when a signal arrives. If you want your
1512system calls to be interrupted by signal delivery then do something like
1513this:
1514.Sp
1515.Vb 1
1516\& use POSIX ':signal_h';
1517.Ve
1518.Sp
1519.Vb 3
1520\& my $alarm = 0;
1521\& sigaction SIGALRM, new POSIX::SigAction sub { $alarm = 1 }
1522\& or die "Error setting SIGALRM handler: $!\en";
1523.Ve
1524.Sp
1525See \s-1POSIX\s0.
1526.Sp
1527Certain internal hooks can be also set using the \f(CW%SIG\fR hash. The
1528routine indicated by \f(CW$SIG{_\|_WARN_\|_}\fR is called when a warning message is
1529about to be printed. The warning message is passed as the first
1530argument. The presence of a _\|_WARN_\|_ hook causes the ordinary printing
1531of warnings to \s-1STDERR\s0 to be suppressed. You can use this to save warnings
1532in a variable, or turn warnings into fatal errors, like this:
1533.Sp
1534.Vb 2
1535\& local $SIG{__WARN__} = sub { die $_[0] };
1536\& eval $proggie;
1537.Ve
1538.Sp
1539The routine indicated by \f(CW$SIG{_\|_DIE_\|_}\fR is called when a fatal exception
1540is about to be thrown. The error message is passed as the first
1541argument. When a _\|_DIE_\|_ hook routine returns, the exception
1542processing continues as it would have in the absence of the hook,
1543unless the hook routine itself exits via a \f(CW\*(C`goto\*(C'\fR, a loop exit, or a \fIdie()\fR.
1544The \f(CW\*(C`_\|_DIE_\|_\*(C'\fR handler is explicitly disabled during the call, so that you
1545can die from a \f(CW\*(C`_\|_DIE_\|_\*(C'\fR handler. Similarly for \f(CW\*(C`_\|_WARN_\|_\*(C'\fR.
1546.Sp
1547Due to an implementation glitch, the \f(CW$SIG{_\|_DIE_\|_}\fR hook is called
1548even inside an \fIeval()\fR. Do not use this to rewrite a pending exception
1549in \f(CW$@\fR, or as a bizarre substitute for overriding \fICORE::GLOBAL::die()\fR.
1550This strange action at a distance may be fixed in a future release
1551so that \f(CW$SIG{_\|_DIE_\|_}\fR is only called if your program is about
1552to exit, as was the original intent. Any other use is deprecated.
1553.Sp
1554\&\f(CW\*(C`_\|_DIE_\|_\*(C'\fR/\f(CW\*(C`_\|_WARN_\|_\*(C'\fR handlers are very special in one respect:
1555they may be called to report (probable) errors found by the parser.
1556In such a case the parser may be in inconsistent state, so any
1557attempt to evaluate Perl code from such a handler will probably
1558result in a segfault. This means that warnings or errors that
1559result from parsing Perl should be used with extreme caution, like
1560this:
1561.Sp
1562.Vb 4
1563\& require Carp if defined $^S;
1564\& Carp::confess("Something wrong") if defined &Carp::confess;
1565\& die "Something wrong, but could not load Carp to give backtrace...
1566\& To see backtrace try starting Perl with -MCarp switch";
1567.Ve
1568.Sp
1569Here the first line will load Carp \fIunless\fR it is the parser who
1570called the handler. The second line will print backtrace and die if
1571Carp was available. The third line will be executed only if Carp was
1572not available.
1573.Sp
1574See \*(L"die\*(R" in perlfunc, \*(L"warn\*(R" in perlfunc, \*(L"eval\*(R" in perlfunc, and
1575warnings for additional information.
1576.Sh "Error Indicators"
1577.IX Subsection "Error Indicators"
1578The variables \f(CW$@\fR, \f(CW$!\fR, \f(CW$^E\fR, and \f(CW$?\fR contain information
1579about different types of error conditions that may appear during
1580execution of a Perl program. The variables are shown ordered by
1581the \*(L"distance\*(R" between the subsystem which reported the error and
1582the Perl process. They correspond to errors detected by the Perl
1583interpreter, C library, operating system, or an external program,
1584respectively.
1585.PP
1586To illustrate the differences between these variables, consider the
1587following Perl expression, which uses a single-quoted string:
1588.PP
1589.Vb 5
1590\& eval q{
1591\& open my $pipe, "/cdrom/install |" or die $!;
1592\& my @res = <$pipe>;
1593\& close $pipe or die "bad pipe: $?, $!";
1594\& };
1595.Ve
1596.PP
1597After execution of this statement all 4 variables may have been set.
1598.PP
1599\&\f(CW$@\fR is set if the string to be \f(CW\*(C`eval\*(C'\fR\-ed did not compile (this
1600may happen if \f(CW\*(C`open\*(C'\fR or \f(CW\*(C`close\*(C'\fR were imported with bad prototypes),
1601or if Perl code executed during evaluation \fIdie()\fRd . In these cases
1602the value of $@ is the compile error, or the argument to \f(CW\*(C`die\*(C'\fR
1603(which will interpolate \f(CW$!\fR and \f(CW$?\fR!). (See also Fatal,
1604though.)
1605.PP
1606When the \fIeval()\fR expression above is executed, \fIopen()\fR, \f(CW\*(C`<PIPE>\*(C'\fR,
1607and \f(CW\*(C`close\*(C'\fR are translated to calls in the C run-time library and
1608thence to the operating system kernel. \f(CW$!\fR is set to the C library's
1609\&\f(CW\*(C`errno\*(C'\fR if one of these calls fails.
1610.PP
1611Under a few operating systems, \f(CW$^E\fR may contain a more verbose
1612error indicator, such as in this case, \*(L"\s-1CDROM\s0 tray not closed.\*(R"
1613Systems that do not support extended error messages leave \f(CW$^E\fR
1614the same as \f(CW$!\fR.
1615.PP
1616Finally, \f(CW$?\fR may be set to non\-0 value if the external program
1617\&\fI/cdrom/install\fR fails. The upper eight bits reflect specific
1618error conditions encountered by the program (the program's \fIexit()\fR
1619value). The lower eight bits reflect mode of failure, like signal
1620death and core dump information See \fIwait\fR\|(2) for details. In
1621contrast to \f(CW$!\fR and \f(CW$^E\fR, which are set only if error condition
1622is detected, the variable \f(CW$?\fR is set on each \f(CW\*(C`wait\*(C'\fR or pipe
1623\&\f(CW\*(C`close\*(C'\fR, overwriting the old value. This is more like \f(CW$@\fR, which
1624on every \fIeval()\fR is always set on failure and cleared on success.
1625.PP
1626For more details, see the individual descriptions at \f(CW$@\fR, \f(CW$!\fR, \f(CW$^E\fR,
1627and \f(CW$?\fR.
1628.Sh "Technical Note on the Syntax of Variable Names"
1629.IX Subsection "Technical Note on the Syntax of Variable Names"
1630Variable names in Perl can have several formats. Usually, they
1631must begin with a letter or underscore, in which case they can be
1632arbitrarily long (up to an internal limit of 251 characters) and
1633may contain letters, digits, underscores, or the special sequence
1634\&\f(CW\*(C`::\*(C'\fR or \f(CW\*(C`'\*(C'\fR. In this case, the part before the last \f(CW\*(C`::\*(C'\fR or
1635\&\f(CW\*(C`'\*(C'\fR is taken to be a \fIpackage qualifier\fR; see perlmod.
1636.PP
1637Perl variable names may also be a sequence of digits or a single
1638punctuation or control character. These names are all reserved for
1639special uses by Perl; for example, the all-digits names are used
1640to hold data captured by backreferences after a regular expression
1641match. Perl has a special syntax for the single-control-character
1642names: It understands \f(CW\*(C`^X\*(C'\fR (caret \f(CW\*(C`X\*(C'\fR) to mean the control\-\f(CW\*(C`X\*(C'\fR
1643character. For example, the notation \f(CW$^W\fR (dollar\-sign caret
1644\&\f(CW\*(C`W\*(C'\fR) is the scalar variable whose name is the single character
1645control\-\f(CW\*(C`W\*(C'\fR. This is better than typing a literal control\-\f(CW\*(C`W\*(C'\fR
1646into your program.
1647.PP
1648Finally, new in Perl 5.6, Perl variable names may be alphanumeric
1649strings that begin with control characters (or better yet, a caret).
1650These variables must be written in the form \f(CW\*(C`${^Foo}\*(C'\fR; the braces
1651are not optional. \f(CW\*(C`${^Foo}\*(C'\fR denotes the scalar variable whose
1652name is a control\-\f(CW\*(C`F\*(C'\fR followed by two \f(CW\*(C`o\*(C'\fR's. These variables are
1653reserved for future special uses by Perl, except for the ones that
1654begin with \f(CW\*(C`^_\*(C'\fR (control\-underscore or caret\-underscore). No
1655control-character name that begins with \f(CW\*(C`^_\*(C'\fR will acquire a special
1656meaning in any future version of Perl; such names may therefore be
1657used safely in programs. \f(CW$^_\fR itself, however, \fIis\fR reserved.
1658.PP
1659Perl identifiers that begin with digits, control characters, or
1660punctuation characters are exempt from the effects of the \f(CW\*(C`package\*(C'\fR
1661declaration and are always forced to be in package \f(CW\*(C`main\*(C'\fR. A few
1662other names are also exempt:
1663.PP
1664.Vb 5
1665\& ENV STDIN
1666\& INC STDOUT
1667\& ARGV STDERR
1668\& ARGVOUT
1669\& SIG
1670.Ve
1671.PP
1672In particular, the new special \f(CW\*(C`${^_XYZ}\*(C'\fR variables are always taken
1673to be in package \f(CW\*(C`main\*(C'\fR, regardless of any \f(CW\*(C`package\*(C'\fR declarations
1674presently in scope.
1675.SH "BUGS"
1676.IX Header "BUGS"
1677Due to an unfortunate accident of Perl's implementation, \f(CW\*(C`use
1678English\*(C'\fR imposes a considerable performance penalty on all regular
1679expression matches in a program, regardless of whether they occur
1680in the scope of \f(CW\*(C`use English\*(C'\fR. For that reason, saying \f(CW\*(C`use
1681English\*(C'\fR in libraries is strongly discouraged. See the
1682Devel::SawAmpersand module documentation from \s-1CPAN\s0
1683( http://www.cpan.org/modules/by\-module/Devel/ )
1684for more information.
1685.PP
1686Having to even think about the \f(CW$^S\fR variable in your exception
1687handlers is simply wrong. \f(CW$SIG{_\|_DIE_\|_}\fR as currently implemented
1688invites grievous and difficult to track down errors. Avoid it
1689and use an \f(CW\*(C`END{}\*(C'\fR or CORE::GLOBAL::die override instead.