1PERLVAR(1) Perl Programmers Reference Guide PERLVAR(1)
2
3
4
6 perlvar - Perl predefined variables
7
9 The Syntax of Variable Names
10 Variable names in Perl can have several formats. Usually, they must
11 begin with a letter or underscore, in which case they can be
12 arbitrarily long (up to an internal limit of 251 characters) and may
13 contain letters, digits, underscores, or the special sequence "::" or
14 "'". In this case, the part before the last "::" or "'" is taken to be
15 a package qualifier; see perlmod. A Unicode letter that is not ASCII
16 is not considered to be a letter unless "use utf8" is in effect, and
17 somewhat more complicated rules apply; see "Identifier parsing" in
18 perldata for details.
19
20 Perl variable names may also be a sequence of digits, a single
21 punctuation character, or the two-character sequence: "^" (caret or
22 CIRCUMFLEX ACCENT) followed by any one of the characters "[][A-Z^_?\]".
23 These names are all reserved for special uses by Perl; for example, the
24 all-digits names are used to hold data captured by backreferences after
25 a regular expression match.
26
27 Since Perl v5.6.0, Perl variable names may also be alphanumeric strings
28 preceded by a caret. These must all be written in the form "${^Foo}";
29 the braces are not optional. "${^Foo}" denotes the scalar variable
30 whose name is considered to be a control-"F" followed by two "o"'s.
31 These variables are reserved for future special uses by Perl, except
32 for the ones that begin with "^_" (caret-underscore). No name that
33 begins with "^_" will acquire a special meaning in any future version
34 of Perl; such names may therefore be used safely in programs. $^_
35 itself, however, is reserved.
36
37 Perl identifiers that begin with digits or punctuation characters are
38 exempt from the effects of the "package" declaration and are always
39 forced to be in package "main"; they are also exempt from "strict
40 'vars'" errors. A few other names are also exempt in these ways:
41
42 ENV STDIN
43 INC STDOUT
44 ARGV STDERR
45 ARGVOUT
46 SIG
47
48 In particular, the special "${^_XYZ}" variables are always taken to be
49 in package "main", regardless of any "package" declarations presently
50 in scope.
51
53 The following names have special meaning to Perl. Most punctuation
54 names have reasonable mnemonics, or analogs in the shells.
55 Nevertheless, if you wish to use long variable names, you need only
56 say:
57
58 use English;
59
60 at the top of your program. This aliases all the short names to the
61 long names in the current package. Some even have medium names,
62 generally borrowed from awk. For more info, please see English.
63
64 Before you continue, note the sort order for variables. In general, we
65 first list the variables in case-insensitive, almost-lexigraphical
66 order (ignoring the "{" or "^" preceding words, as in "${^UNICODE}" or
67 $^T), although $_ and @_ move up to the top of the pile. For variables
68 with the same identifier, we list it in order of scalar, array, hash,
69 and bareword.
70
71 General Variables
72 $ARG
73 $_ The default input and pattern-searching space. The following
74 pairs are equivalent:
75
76 while (<>) {...} # equivalent only in while!
77 while (defined($_ = <>)) {...}
78
79 /^Subject:/
80 $_ =~ /^Subject:/
81
82 tr/a-z/A-Z/
83 $_ =~ tr/a-z/A-Z/
84
85 chomp
86 chomp($_)
87
88 Here are the places where Perl will assume $_ even if you don't
89 use it:
90
91 • The following functions use $_ as a default argument:
92
93 abs, alarm, chomp, chop, chr, chroot, cos, defined, eval,
94 evalbytes, exp, fc, glob, hex, int, lc, lcfirst, length,
95 log, lstat, mkdir, oct, ord, pos, print, printf, quotemeta,
96 readlink, readpipe, ref, require, reverse (in scalar context
97 only), rmdir, say, sin, split (for its second argument),
98 sqrt, stat, study, uc, ucfirst, unlink, unpack.
99
100 • All file tests ("-f", "-d") except for "-t", which defaults
101 to STDIN. See "-X" in perlfunc
102
103 • The pattern matching operations "m//", "s///" and "tr///"
104 (aka "y///") when used without an "=~" operator.
105
106 • The default iterator variable in a "foreach" loop if no
107 other variable is supplied.
108
109 • The implicit iterator variable in the "grep()" and "map()"
110 functions.
111
112 • The implicit variable of "given()".
113
114 • The default place to put the next value or input record when
115 a "<FH>", "readline", "readdir" or "each" operation's result
116 is tested by itself as the sole criterion of a "while" test.
117 Outside a "while" test, this will not happen.
118
119 $_ is a global variable.
120
121 However, between perl v5.10.0 and v5.24.0, it could be used
122 lexically by writing "my $_". Making $_ refer to the global $_
123 in the same scope was then possible with "our $_". This
124 experimental feature was removed and is now a fatal error, but
125 you may encounter it in older code.
126
127 Mnemonic: underline is understood in certain operations.
128
129 @ARG
130 @_ Within a subroutine the array @_ contains the parameters passed
131 to that subroutine. Inside a subroutine, @_ is the default
132 array for the array operators "pop" and "shift".
133
134 See perlsub.
135
136 $LIST_SEPARATOR
137 $" When an array or an array slice is interpolated into a double-
138 quoted string or a similar context such as "/.../", its
139 elements are separated by this value. Default is a space. For
140 example, this:
141
142 print "The array is: @array\n";
143
144 is equivalent to this:
145
146 print "The array is: " . join($", @array) . "\n";
147
148 Mnemonic: works in double-quoted context.
149
150 $PROCESS_ID
151 $PID
152 $$ The process number of the Perl running this script. Though you
153 can set this variable, doing so is generally discouraged,
154 although it can be invaluable for some testing purposes. It
155 will be reset automatically across "fork()" calls.
156
157 Note for Linux and Debian GNU/kFreeBSD users: Before Perl
158 v5.16.0 perl would emulate POSIX semantics on Linux systems
159 using LinuxThreads, a partial implementation of POSIX Threads
160 that has since been superseded by the Native POSIX Thread
161 Library (NPTL).
162
163 LinuxThreads is now obsolete on Linux, and caching "getpid()"
164 like this made embedding perl unnecessarily complex (since
165 you'd have to manually update the value of $$), so now $$ and
166 "getppid()" will always return the same values as the
167 underlying C library.
168
169 Debian GNU/kFreeBSD systems also used LinuxThreads up until and
170 including the 6.0 release, but after that moved to FreeBSD
171 thread semantics, which are POSIX-like.
172
173 To see if your system is affected by this discrepancy check if
174 "getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL" returns a false
175 value. NTPL threads preserve the POSIX semantics.
176
177 Mnemonic: same as shells.
178
179 $PROGRAM_NAME
180 $0 Contains the name of the program being executed.
181
182 On some (but not all) operating systems assigning to $0
183 modifies the argument area that the "ps" program sees. On some
184 platforms you may have to use special "ps" options or a
185 different "ps" to see the changes. Modifying the $0 is more
186 useful as a way of indicating the current program state than it
187 is for hiding the program you're running.
188
189 Note that there are platform-specific limitations on the
190 maximum length of $0. In the most extreme case it may be
191 limited to the space occupied by the original $0.
192
193 In some platforms there may be arbitrary amount of padding, for
194 example space characters, after the modified name as shown by
195 "ps". In some platforms this padding may extend all the way to
196 the original length of the argument area, no matter what you do
197 (this is the case for example with Linux 2.2).
198
199 Note for BSD users: setting $0 does not completely remove
200 "perl" from the ps(1) output. For example, setting $0 to
201 "foobar" may result in "perl: foobar (perl)" (whether both the
202 "perl: " prefix and the " (perl)" suffix are shown depends on
203 your exact BSD variant and version). This is an operating
204 system feature, Perl cannot help it.
205
206 In multithreaded scripts Perl coordinates the threads so that
207 any thread may modify its copy of the $0 and the change becomes
208 visible to ps(1) (assuming the operating system plays along).
209 Note that the view of $0 the other threads have will not change
210 since they have their own copies of it.
211
212 If the program has been given to perl via the switches "-e" or
213 "-E", $0 will contain the string "-e".
214
215 On Linux as of perl v5.14.0 the legacy process name will be set
216 with prctl(2), in addition to altering the POSIX name via
217 "argv[0]" as perl has done since version 4.000. Now system
218 utilities that read the legacy process name such as ps, top and
219 killall will recognize the name you set when assigning to $0.
220 The string you supply will be cut off at 16 bytes, this is a
221 limitation imposed by Linux.
222
223 Mnemonic: same as sh and ksh.
224
225 $REAL_GROUP_ID
226 $GID
227 $( The real gid of this process. If you are on a machine that
228 supports membership in multiple groups simultaneously, gives a
229 space separated list of groups you are in. The first number is
230 the one returned by "getgid()", and the subsequent ones by
231 "getgroups()", one of which may be the same as the first
232 number.
233
234 However, a value assigned to $( must be a single number used to
235 set the real gid. So the value given by $( should not be
236 assigned back to $( without being forced numeric, such as by
237 adding zero. Note that this is different to the effective gid
238 ($)) which does take a list.
239
240 You can change both the real gid and the effective gid at the
241 same time by using "POSIX::setgid()". Changes to $( require a
242 check to $! to detect any possible errors after an attempted
243 change.
244
245 Mnemonic: parentheses are used to group things. The real gid
246 is the group you left, if you're running setgid.
247
248 $EFFECTIVE_GROUP_ID
249 $EGID
250 $) The effective gid of this process. If you are on a machine
251 that supports membership in multiple groups simultaneously,
252 gives a space separated list of groups you are in. The first
253 number is the one returned by "getegid()", and the subsequent
254 ones by "getgroups()", one of which may be the same as the
255 first number.
256
257 Similarly, a value assigned to $) must also be a space-
258 separated list of numbers. The first number sets the effective
259 gid, and the rest (if any) are passed to "setgroups()". To get
260 the effect of an empty list for "setgroups()", just repeat the
261 new effective gid; that is, to force an effective gid of 5 and
262 an effectively empty "setgroups()" list, say " $) = "5 5" ".
263
264 You can change both the effective gid and the real gid at the
265 same time by using "POSIX::setgid()" (use only a single numeric
266 argument). Changes to $) require a check to $! to detect any
267 possible errors after an attempted change.
268
269 $<, $>, $( and $) can be set only on machines that support the
270 corresponding set[re][ug]id() routine. $( and $) can be
271 swapped only on machines supporting "setregid()".
272
273 Mnemonic: parentheses are used to group things. The effective
274 gid is the group that's right for you, if you're running
275 setgid.
276
277 $REAL_USER_ID
278 $UID
279 $< The real uid of this process. You can change both the real uid
280 and the effective uid at the same time by using
281 "POSIX::setuid()". Since changes to $< require a system call,
282 check $! after a change attempt to detect any possible errors.
283
284 Mnemonic: it's the uid you came from, if you're running setuid.
285
286 $EFFECTIVE_USER_ID
287 $EUID
288 $> The effective uid of this process. For example:
289
290 $< = $>; # set real to effective uid
291 ($<,$>) = ($>,$<); # swap real and effective uids
292
293 You can change both the effective uid and the real uid at the
294 same time by using "POSIX::setuid()". Changes to $> require a
295 check to $! to detect any possible errors after an attempted
296 change.
297
298 $< and $> can be swapped only on machines supporting
299 "setreuid()".
300
301 Mnemonic: it's the uid you went to, if you're running setuid.
302
303 $SUBSCRIPT_SEPARATOR
304 $SUBSEP
305 $; The subscript separator for multidimensional array emulation.
306 If you refer to a hash element as
307
308 $foo{$x,$y,$z}
309
310 it really means
311
312 $foo{join($;, $x, $y, $z)}
313
314 But don't put
315
316 @foo{$x,$y,$z} # a slice--note the @
317
318 which means
319
320 ($foo{$x},$foo{$y},$foo{$z})
321
322 Default is "\034", the same as SUBSEP in awk. If your keys
323 contain binary data there might not be any safe value for $;.
324
325 Consider using "real" multidimensional arrays as described in
326 perllol.
327
328 Mnemonic: comma (the syntactic subscript separator) is a semi-
329 semicolon.
330
331 $a
332 $b Special package variables when using "sort()", see "sort" in
333 perlfunc. Because of this specialness $a and $b don't need to
334 be declared (using "use vars", or "our()") even when using the
335 "strict 'vars'" pragma. Don't lexicalize them with "my $a" or
336 "my $b" if you want to be able to use them in the "sort()"
337 comparison block or function.
338
339 %ENV The hash %ENV contains your current environment. Setting a
340 value in "ENV" changes the environment for any child processes
341 you subsequently "fork()" off.
342
343 As of v5.18.0, both keys and values stored in %ENV are
344 stringified.
345
346 my $foo = 1;
347 $ENV{'bar'} = \$foo;
348 if( ref $ENV{'bar'} ) {
349 say "Pre 5.18.0 Behaviour";
350 } else {
351 say "Post 5.18.0 Behaviour";
352 }
353
354 Previously, only child processes received stringified values:
355
356 my $foo = 1;
357 $ENV{'bar'} = \$foo;
358
359 # Always printed 'non ref'
360 system($^X, '-e',
361 q/print ( ref $ENV{'bar'} ? 'ref' : 'non ref' ) /);
362
363 This happens because you can't really share arbitrary data
364 structures with foreign processes.
365
366 $OLD_PERL_VERSION
367 $] The revision, version, and subversion of the Perl interpreter,
368 represented as a decimal of the form 5.XXXYYY, where XXX is the
369 version / 1e3 and YYY is the subversion / 1e6. For example,
370 Perl v5.10.1 would be "5.010001".
371
372 This variable can be used to determine whether the Perl
373 interpreter executing a script is in the right range of
374 versions:
375
376 warn "No PerlIO!\n" if "$]" < 5.008;
377
378 When comparing $], numeric comparison operators should be used,
379 but the variable should be stringified first to avoid issues
380 where its original numeric value is inaccurate.
381
382 See also the documentation of "use VERSION" and "require
383 VERSION" for a convenient way to fail if the running Perl
384 interpreter is too old.
385
386 See "$^V" for a representation of the Perl version as a version
387 object, which allows more flexible string comparisons.
388
389 The main advantage of $] over $^V is that it works the same on
390 any version of Perl. The disadvantages are that it can't
391 easily be compared to versions in other formats (e.g. literal
392 v-strings, "v1.2.3" or version objects) and numeric comparisons
393 are subject to the binary floating point representation; it's
394 good for numeric literal version checks and bad for comparing
395 to a variable that hasn't been sanity-checked.
396
397 The $OLD_PERL_VERSION form was added in Perl v5.20.0 for
398 historical reasons but its use is discouraged. (If your reason
399 to use $] is to run code on old perls then referring to it as
400 $OLD_PERL_VERSION would be self-defeating.)
401
402 Mnemonic: Is this version of perl in the right bracket?
403
404 $SYSTEM_FD_MAX
405 $^F The maximum system file descriptor, ordinarily 2. System file
406 descriptors are passed to "exec()"ed processes, while higher
407 file descriptors are not. Also, during an "open()", system
408 file descriptors are preserved even if the "open()" fails
409 (ordinary file descriptors are closed before the "open()" is
410 attempted). The close-on-exec status of a file descriptor will
411 be decided according to the value of $^F when the corresponding
412 file, pipe, or socket was opened, not the time of the "exec()".
413
414 @F The array @F contains the fields of each line read in when
415 autosplit mode is turned on. See perlrun for the -a switch.
416 This array is package-specific, and must be declared or given a
417 full package name if not in package main when running under
418 "strict 'vars'".
419
420 @INC The array @INC contains the list of places that the "do EXPR",
421 "require", or "use" constructs look for their library files.
422 It initially consists of the arguments to any -I command-line
423 switches, followed by the default Perl library, probably
424 /usr/local/lib/perl. Prior to Perl 5.26, "." -which represents
425 the current directory, was included in @INC; it has been
426 removed. This change in behavior is documented in
427 "PERL_USE_UNSAFE_INC" and it is not recommended that "." be re-
428 added to @INC. If you need to modify @INC at runtime, you
429 should use the "use lib" pragma to get the machine-dependent
430 library properly loaded as well:
431
432 use lib '/mypath/libdir/';
433 use SomeMod;
434
435 You can also insert hooks into the file inclusion system by
436 putting Perl code directly into @INC. Those hooks may be
437 subroutine references, array references or blessed objects.
438 See "require" in perlfunc for details.
439
440 %INC The hash %INC contains entries for each filename included via
441 the "do", "require", or "use" operators. The key is the
442 filename you specified (with module names converted to
443 pathnames), and the value is the location of the file found.
444 The "require" operator uses this hash to determine whether a
445 particular file has already been included.
446
447 If the file was loaded via a hook (e.g. a subroutine reference,
448 see "require" in perlfunc for a description of these hooks),
449 this hook is by default inserted into %INC in place of a
450 filename. Note, however, that the hook may have set the %INC
451 entry by itself to provide some more specific info.
452
453 $INPLACE_EDIT
454 $^I The current value of the inplace-edit extension. Use "undef"
455 to disable inplace editing.
456
457 Mnemonic: value of -i switch.
458
459 @ISA Each package contains a special array called @ISA which
460 contains a list of that class's parent classes, if any. This
461 array is simply a list of scalars, each of which is a string
462 that corresponds to a package name. The array is examined when
463 Perl does method resolution, which is covered in perlobj.
464
465 To load packages while adding them to @ISA, see the parent
466 pragma. The discouraged base pragma does this as well, but
467 should not be used except when compatibility with the
468 discouraged fields pragma is required.
469
470 $^M By default, running out of memory is an untrappable, fatal
471 error. However, if suitably built, Perl can use the contents
472 of $^M as an emergency memory pool after "die()"ing. Suppose
473 that your Perl were compiled with "-DPERL_EMERGENCY_SBRK" and
474 used Perl's malloc. Then
475
476 $^M = 'a' x (1 << 16);
477
478 would allocate a 64K buffer for use in an emergency. See the
479 INSTALL file in the Perl distribution for information on how to
480 add custom C compilation flags when compiling perl. To
481 discourage casual use of this advanced feature, there is no
482 English long name for this variable.
483
484 This variable was added in Perl 5.004.
485
486 $OSNAME
487 $^O The name of the operating system under which this copy of Perl
488 was built, as determined during the configuration process. For
489 examples see "PLATFORMS" in perlport.
490
491 The value is identical to $Config{'osname'}. See also Config
492 and the -V command-line switch documented in perlrun.
493
494 In Windows platforms, $^O is not very helpful: since it is
495 always "MSWin32", it doesn't tell the difference between
496 95/98/ME/NT/2000/XP/CE/.NET. Use "Win32::GetOSName()" or
497 Win32::GetOSVersion() (see Win32 and perlport) to distinguish
498 between the variants.
499
500 This variable was added in Perl 5.003.
501
502 %SIG The hash %SIG contains signal handlers for signals. For
503 example:
504
505 sub handler { # 1st argument is signal name
506 my($sig) = @_;
507 print "Caught a SIG$sig--shutting down\n";
508 close(LOG);
509 exit(0);
510 }
511
512 $SIG{'INT'} = \&handler;
513 $SIG{'QUIT'} = \&handler;
514 ...
515 $SIG{'INT'} = 'DEFAULT'; # restore default action
516 $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT
517
518 Using a value of 'IGNORE' usually has the effect of ignoring
519 the signal, except for the "CHLD" signal. See perlipc for more
520 about this special case. Using an empty string or "undef" as
521 the value has the same effect as 'DEFAULT'.
522
523 Here are some other examples:
524
525 $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not
526 # recommended)
527 $SIG{"PIPE"} = \&Plumber; # just fine; assume current
528 # Plumber
529 $SIG{"PIPE"} = *Plumber; # somewhat esoteric
530 $SIG{"PIPE"} = Plumber(); # oops, what did Plumber()
531 # return??
532
533 Be sure not to use a bareword as the name of a signal handler,
534 lest you inadvertently call it.
535
536 Using a string that doesn't correspond to any existing function
537 or a glob that doesn't contain a code slot is equivalent to
538 'IGNORE', but a warning is emitted when the handler is being
539 called (the warning is not emitted for the internal hooks
540 described below).
541
542 If your system has the "sigaction()" function then signal
543 handlers are installed using it. This means you get reliable
544 signal handling.
545
546 The default delivery policy of signals changed in Perl v5.8.0
547 from immediate (also known as "unsafe") to deferred, also known
548 as "safe signals". See perlipc for more information.
549
550 Certain internal hooks can be also set using the %SIG hash.
551 The routine indicated by $SIG{__WARN__} is called when a
552 warning message is about to be printed. The warning message is
553 passed as the first argument. The presence of a "__WARN__"
554 hook causes the ordinary printing of warnings to "STDERR" to be
555 suppressed. You can use this to save warnings in a variable,
556 or turn warnings into fatal errors, like this:
557
558 local $SIG{__WARN__} = sub { die $_[0] };
559 eval $proggie;
560
561 As the 'IGNORE' hook is not supported by "__WARN__", its effect
562 is the same as using 'DEFAULT'. You can disable warnings using
563 the empty subroutine:
564
565 local $SIG{__WARN__} = sub {};
566
567 The routine indicated by $SIG{__DIE__} is called when a fatal
568 exception is about to be thrown. The error message is passed
569 as the first argument. When a "__DIE__" hook routine returns,
570 the exception processing continues as it would have in the
571 absence of the hook, unless the hook routine itself exits via a
572 "goto &sub", a loop exit, or a "die()". The "__DIE__" handler
573 is explicitly disabled during the call, so that you can die
574 from a "__DIE__" handler. Similarly for "__WARN__".
575
576 The $SIG{__DIE__} hook is called even inside an "eval()". It
577 was never intended to happen this way, but an implementation
578 glitch made this possible. This used to be deprecated, as it
579 allowed strange action at a distance like rewriting a pending
580 exception in $@. Plans to rectify this have been scrapped, as
581 users found that rewriting a pending exception is actually a
582 useful feature, and not a bug.
583
584 The $SIG{__DIE__} doesn't support 'IGNORE'; it has the same
585 effect as 'DEFAULT'.
586
587 "__DIE__"/"__WARN__" handlers are very special in one respect:
588 they may be called to report (probable) errors found by the
589 parser. In such a case the parser may be in inconsistent
590 state, so any attempt to evaluate Perl code from such a handler
591 will probably result in a segfault. This means that warnings
592 or errors that result from parsing Perl should be used with
593 extreme caution, like this:
594
595 require Carp if defined $^S;
596 Carp::confess("Something wrong") if defined &Carp::confess;
597 die "Something wrong, but could not load Carp to give "
598 . "backtrace...\n\t"
599 . "To see backtrace try starting Perl with -MCarp switch";
600
601 Here the first line will load "Carp" unless it is the parser
602 who called the handler. The second line will print backtrace
603 and die if "Carp" was available. The third line will be
604 executed only if "Carp" was not available.
605
606 Having to even think about the $^S variable in your exception
607 handlers is simply wrong. $SIG{__DIE__} as currently
608 implemented invites grievous and difficult to track down
609 errors. Avoid it and use an "END{}" or CORE::GLOBAL::die
610 override instead.
611
612 See "die" in perlfunc, "warn" in perlfunc, "eval" in perlfunc,
613 and warnings for additional information.
614
615 $BASETIME
616 $^T The time at which the program began running, in seconds since
617 the epoch (beginning of 1970). The values returned by the -M,
618 -A, and -C filetests are based on this value.
619
620 $PERL_VERSION
621 $^V The revision, version, and subversion of the Perl interpreter,
622 represented as a version object.
623
624 This variable first appeared in perl v5.6.0; earlier versions
625 of perl will see an undefined value. Before perl v5.10.0 $^V
626 was represented as a v-string rather than a version object.
627
628 $^V can be used to determine whether the Perl interpreter
629 executing a script is in the right range of versions. For
630 example:
631
632 warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1
633
634 While version objects overload stringification, to portably
635 convert $^V into its string representation, use "sprintf()"'s
636 "%vd" conversion, which works for both v-strings or version
637 objects:
638
639 printf "version is v%vd\n", $^V; # Perl's version
640
641 See the documentation of "use VERSION" and "require VERSION"
642 for a convenient way to fail if the running Perl interpreter is
643 too old.
644
645 See also "$]" for a decimal representation of the Perl version.
646
647 The main advantage of $^V over $] is that, for Perl v5.10.0 or
648 later, it overloads operators, allowing easy comparison against
649 other version representations (e.g. decimal, literal v-string,
650 "v1.2.3", or objects). The disadvantage is that prior to
651 v5.10.0, it was only a literal v-string, which can't be easily
652 printed or compared, whereas the behavior of $] is unchanged on
653 all versions of Perl.
654
655 Mnemonic: use ^V for a version object.
656
657 ${^WIN32_SLOPPY_STAT}
658 This variable no longer has any function.
659
660 This variable was added in Perl v5.10.0 and removed in Perl
661 v5.34.0.
662
663 $EXECUTABLE_NAME
664 $^X The name used to execute the current copy of Perl, from C's
665 "argv[0]" or (where supported) /proc/self/exe.
666
667 Depending on the host operating system, the value of $^X may be
668 a relative or absolute pathname of the perl program file, or
669 may be the string used to invoke perl but not the pathname of
670 the perl program file. Also, most operating systems permit
671 invoking programs that are not in the PATH environment
672 variable, so there is no guarantee that the value of $^X is in
673 PATH. For VMS, the value may or may not include a version
674 number.
675
676 You usually can use the value of $^X to re-invoke an
677 independent copy of the same perl that is currently running,
678 e.g.,
679
680 @first_run = `$^X -le "print int rand 100 for 1..100"`;
681
682 But recall that not all operating systems support forking or
683 capturing of the output of commands, so this complex statement
684 may not be portable.
685
686 It is not safe to use the value of $^X as a path name of a
687 file, as some operating systems that have a mandatory suffix on
688 executable files do not require use of the suffix when invoking
689 a command. To convert the value of $^X to a path name, use the
690 following statements:
691
692 # Build up a set of file names (not command names).
693 use Config;
694 my $this_perl = $^X;
695 if ($^O ne 'VMS') {
696 $this_perl .= $Config{_exe}
697 unless $this_perl =~ m/$Config{_exe}$/i;
698 }
699
700 Because many operating systems permit anyone with read access
701 to the Perl program file to make a copy of it, patch the copy,
702 and then execute the copy, the security-conscious Perl
703 programmer should take care to invoke the installed copy of
704 perl, not the copy referenced by $^X. The following statements
705 accomplish this goal, and produce a pathname that can be
706 invoked as a command or referenced as a file.
707
708 use Config;
709 my $secure_perl_path = $Config{perlpath};
710 if ($^O ne 'VMS') {
711 $secure_perl_path .= $Config{_exe}
712 unless $secure_perl_path =~ m/$Config{_exe}$/i;
713 }
714
715 Variables related to regular expressions
716 Most of the special variables related to regular expressions are side
717 effects. Perl sets these variables when it has a successful match, so
718 you should check the match result before using them. For instance:
719
720 if( /P(A)TT(ER)N/ ) {
721 print "I found $1 and $2\n";
722 }
723
724 These variables are read-only and dynamically-scoped, unless we note
725 otherwise.
726
727 The dynamic nature of the regular expression variables means that their
728 value is limited to the block that they are in, as demonstrated by this
729 bit of code:
730
731 my $outer = 'Wallace and Grommit';
732 my $inner = 'Mutt and Jeff';
733
734 my $pattern = qr/(\S+) and (\S+)/;
735
736 sub show_n { print "\$1 is $1; \$2 is $2\n" }
737
738 {
739 OUTER:
740 show_n() if $outer =~ m/$pattern/;
741
742 INNER: {
743 show_n() if $inner =~ m/$pattern/;
744 }
745
746 show_n();
747 }
748
749 The output shows that while in the "OUTER" block, the values of $1 and
750 $2 are from the match against $outer. Inside the "INNER" block, the
751 values of $1 and $2 are from the match against $inner, but only until
752 the end of the block (i.e. the dynamic scope). After the "INNER" block
753 completes, the values of $1 and $2 return to the values for the match
754 against $outer even though we have not made another match:
755
756 $1 is Wallace; $2 is Grommit
757 $1 is Mutt; $2 is Jeff
758 $1 is Wallace; $2 is Grommit
759
760 Performance issues
761
762 Traditionally in Perl, any use of any of the three variables "$`", $&
763 or "$'" (or their "use English" equivalents) anywhere in the code,
764 caused all subsequent successful pattern matches to make a copy of the
765 matched string, in case the code might subsequently access one of those
766 variables. This imposed a considerable performance penalty across the
767 whole program, so generally the use of these variables has been
768 discouraged.
769
770 In Perl 5.6.0 the "@-" and "@+" dynamic arrays were introduced that
771 supply the indices of successful matches. So you could for example do
772 this:
773
774 $str =~ /pattern/;
775
776 print $`, $&, $'; # bad: performance hit
777
778 print # good: no performance hit
779 substr($str, 0, $-[0]),
780 substr($str, $-[0], $+[0]-$-[0]),
781 substr($str, $+[0]);
782
783 In Perl 5.10.0 the "/p" match operator flag and the "${^PREMATCH}",
784 "${^MATCH}", and "${^POSTMATCH}" variables were introduced, that
785 allowed you to suffer the penalties only on patterns marked with "/p".
786
787 In Perl 5.18.0 onwards, perl started noting the presence of each of the
788 three variables separately, and only copied that part of the string
789 required; so in
790
791 $`; $&; "abcdefgh" =~ /d/
792
793 perl would only copy the "abcd" part of the string. That could make a
794 big difference in something like
795
796 $str = 'x' x 1_000_000;
797 $&; # whoops
798 $str =~ /x/g # one char copied a million times, not a million chars
799
800 In Perl 5.20.0 a new copy-on-write system was enabled by default, which
801 finally fixes all performance issues with these three variables, and
802 makes them safe to use anywhere.
803
804 The "Devel::NYTProf" and "Devel::FindAmpersand" modules can help you
805 find uses of these problematic match variables in your code.
806
807 $<digits> ($1, $2, ...)
808 Contains the subpattern from the corresponding set of capturing
809 parentheses from the last successful pattern match, not
810 counting patterns matched in nested blocks that have been
811 exited already.
812
813 Note there is a distinction between a capture buffer which
814 matches the empty string a capture buffer which is optional.
815 Eg, "(x?)" and "(x)?" The latter may be undef, the former not.
816
817 These variables are read-only and dynamically-scoped.
818
819 Mnemonic: like \digits.
820
821 @{^CAPTURE}
822 An array which exposes the contents of the capture buffers, if
823 any, of the last successful pattern match, not counting
824 patterns matched in nested blocks that have been exited
825 already.
826
827 Note that the 0 index of @{^CAPTURE} is equivalent to $1, the 1
828 index is equivalent to $2, etc.
829
830 if ("foal"=~/(.)(.)(.)(.)/) {
831 print join "-", @{^CAPTURE};
832 }
833
834 should output "f-o-a-l".
835
836 See also "$<digits> ($1, $2, ...)", "%{^CAPTURE}" and
837 "%{^CAPTURE_ALL}".
838
839 Note that unlike most other regex magic variables there is no
840 single letter equivalent to "@{^CAPTURE}".
841
842 This variable was added in 5.25.7
843
844 $MATCH
845 $& The string matched by the last successful pattern match (not
846 counting any matches hidden within a BLOCK or "eval()" enclosed
847 by the current BLOCK).
848
849 See "Performance issues" above for the serious performance
850 implications of using this variable (even once) in your code.
851
852 This variable is read-only and dynamically-scoped.
853
854 Mnemonic: like "&" in some editors.
855
856 ${^MATCH}
857 This is similar to $& ($MATCH) except that it does not incur
858 the performance penalty associated with that variable.
859
860 See "Performance issues" above.
861
862 In Perl v5.18 and earlier, it is only guaranteed to return a
863 defined value when the pattern was compiled or executed with
864 the "/p" modifier. In Perl v5.20, the "/p" modifier does
865 nothing, so "${^MATCH}" does the same thing as $MATCH.
866
867 This variable was added in Perl v5.10.0.
868
869 This variable is read-only and dynamically-scoped.
870
871 $PREMATCH
872 $` The string preceding whatever was matched by the last
873 successful pattern match, not counting any matches hidden
874 within a BLOCK or "eval" enclosed by the current BLOCK.
875
876 See "Performance issues" above for the serious performance
877 implications of using this variable (even once) in your code.
878
879 This variable is read-only and dynamically-scoped.
880
881 Mnemonic: "`" often precedes a quoted string.
882
883 ${^PREMATCH}
884 This is similar to "$`" ($PREMATCH) except that it does not
885 incur the performance penalty associated with that variable.
886
887 See "Performance issues" above.
888
889 In Perl v5.18 and earlier, it is only guaranteed to return a
890 defined value when the pattern was compiled or executed with
891 the "/p" modifier. In Perl v5.20, the "/p" modifier does
892 nothing, so "${^PREMATCH}" does the same thing as $PREMATCH.
893
894 This variable was added in Perl v5.10.0.
895
896 This variable is read-only and dynamically-scoped.
897
898 $POSTMATCH
899 $' The string following whatever was matched by the last
900 successful pattern match (not counting any matches hidden
901 within a BLOCK or "eval()" enclosed by the current BLOCK).
902 Example:
903
904 local $_ = 'abcdefghi';
905 /def/;
906 print "$`:$&:$'\n"; # prints abc:def:ghi
907
908 See "Performance issues" above for the serious performance
909 implications of using this variable (even once) in your code.
910
911 This variable is read-only and dynamically-scoped.
912
913 Mnemonic: "'" often follows a quoted string.
914
915 ${^POSTMATCH}
916 This is similar to "$'" ($POSTMATCH) except that it does not
917 incur the performance penalty associated with that variable.
918
919 See "Performance issues" above.
920
921 In Perl v5.18 and earlier, it is only guaranteed to return a
922 defined value when the pattern was compiled or executed with
923 the "/p" modifier. In Perl v5.20, the "/p" modifier does
924 nothing, so "${^POSTMATCH}" does the same thing as $POSTMATCH.
925
926 This variable was added in Perl v5.10.0.
927
928 This variable is read-only and dynamically-scoped.
929
930 $LAST_PAREN_MATCH
931 $+ The text matched by the highest used capture group of the last
932 successful search pattern. It is logically equivalent to the
933 highest numbered capture variable ($1, $2, ...) which has a
934 defined value.
935
936 This is useful if you don't know which one of a set of
937 alternative patterns matched. For example:
938
939 /Version: (.*)|Revision: (.*)/ && ($rev = $+);
940
941 This variable is read-only and dynamically-scoped.
942
943 Mnemonic: be positive and forward looking.
944
945 $LAST_SUBMATCH_RESULT
946 $^N The text matched by the used group most-recently closed (i.e.
947 the group with the rightmost closing parenthesis) of the last
948 successful search pattern. This is subtly different from $+.
949 For example in
950
951 "ab" =~ /^((.)(.))$/
952
953 we have
954
955 $1,$^N have the value "ab"
956 $2 has the value "a"
957 $3,$+ have the value "b"
958
959 This is primarily used inside "(?{...})" blocks for examining
960 text recently matched. For example, to effectively capture
961 text to a variable (in addition to $1, $2, etc.), replace
962 "(...)" with
963
964 (?:(...)(?{ $var = $^N }))
965
966 By setting and then using $var in this way relieves you from
967 having to worry about exactly which numbered set of parentheses
968 they are.
969
970 This variable was added in Perl v5.8.0.
971
972 Mnemonic: the (possibly) Nested parenthesis that most recently
973 closed.
974
975 @LAST_MATCH_END
976 @+ This array holds the offsets of the ends of the last successful
977 submatches in the currently active dynamic scope. $+[0] is the
978 offset into the string of the end of the entire match. This is
979 the same value as what the "pos" function returns when called
980 on the variable that was matched against. The nth element of
981 this array holds the offset of the nth submatch, so $+[1] is
982 the offset past where $1 ends, $+[2] the offset past where $2
983 ends, and so on. You can use $#+ to determine how many
984 subgroups were in the last successful match. See the examples
985 given for the "@-" variable.
986
987 This variable was added in Perl v5.6.0.
988
989 %{^CAPTURE}
990 %LAST_PAREN_MATCH
991 %+ Similar to "@+", the "%+" hash allows access to the named
992 capture buffers, should they exist, in the last successful
993 match in the currently active dynamic scope.
994
995 For example, $+{foo} is equivalent to $1 after the following
996 match:
997
998 'foo' =~ /(?<foo>foo)/;
999
1000 The keys of the "%+" hash list only the names of buffers that
1001 have captured (and that are thus associated to defined values).
1002
1003 If multiple distinct capture groups have the same name, then
1004 $+{NAME} will refer to the leftmost defined group in the match.
1005
1006 The underlying behaviour of "%+" is provided by the
1007 Tie::Hash::NamedCapture module.
1008
1009 Note: "%-" and "%+" are tied views into a common internal hash
1010 associated with the last successful regular expression.
1011 Therefore mixing iterative access to them via "each" may have
1012 unpredictable results. Likewise, if the last successful match
1013 changes, then the results may be surprising.
1014
1015 This variable was added in Perl v5.10.0. The "%{^CAPTURE}"
1016 alias was added in 5.25.7.
1017
1018 This variable is read-only and dynamically-scoped.
1019
1020 @LAST_MATCH_START
1021 @- "$-[0]" is the offset of the start of the last successful
1022 match. "$-[n]" is the offset of the start of the substring
1023 matched by n-th subpattern, or undef if the subpattern did not
1024 match.
1025
1026 Thus, after a match against $_, $& coincides with "substr $_,
1027 $-[0], $+[0] - $-[0]". Similarly, $n coincides with "substr
1028 $_, $-[n], $+[n] - $-[n]" if "$-[n]" is defined, and $+
1029 coincides with "substr $_, $-[$#-], $+[$#-] - $-[$#-]". One
1030 can use "$#-" to find the last matched subgroup in the last
1031 successful match. Contrast with $#+, the number of subgroups
1032 in the regular expression. Compare with "@+".
1033
1034 This array holds the offsets of the beginnings of the last
1035 successful submatches in the currently active dynamic scope.
1036 "$-[0]" is the offset into the string of the beginning of the
1037 entire match. The nth element of this array holds the offset
1038 of the nth submatch, so "$-[1]" is the offset where $1 begins,
1039 "$-[2]" the offset where $2 begins, and so on.
1040
1041 After a match against some variable $var:
1042
1043 "$`" is the same as "substr($var, 0, $-[0])"
1044 $& is the same as "substr($var, $-[0], $+[0] - $-[0])"
1045 "$'" is the same as "substr($var, $+[0])"
1046 $1 is the same as "substr($var, $-[1], $+[1] - $-[1])"
1047 $2 is the same as "substr($var, $-[2], $+[2] - $-[2])"
1048 $3 is the same as "substr($var, $-[3], $+[3] - $-[3])"
1049
1050 This variable was added in Perl v5.6.0.
1051
1052 %{^CAPTURE_ALL}
1053 %- Similar to "%+", this variable allows access to the named
1054 capture groups in the last successful match in the currently
1055 active dynamic scope. To each capture group name found in the
1056 regular expression, it associates a reference to an array
1057 containing the list of values captured by all buffers with that
1058 name (should there be several of them), in the order where they
1059 appear.
1060
1061 Here's an example:
1062
1063 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
1064 foreach my $bufname (sort keys %-) {
1065 my $ary = $-{$bufname};
1066 foreach my $idx (0..$#$ary) {
1067 print "\$-{$bufname}[$idx] : ",
1068 (defined($ary->[$idx])
1069 ? "'$ary->[$idx]'"
1070 : "undef"),
1071 "\n";
1072 }
1073 }
1074 }
1075
1076 would print out:
1077
1078 $-{A}[0] : '1'
1079 $-{A}[1] : '3'
1080 $-{B}[0] : '2'
1081 $-{B}[1] : '4'
1082
1083 The keys of the "%-" hash correspond to all buffer names found
1084 in the regular expression.
1085
1086 The behaviour of "%-" is implemented via the
1087 Tie::Hash::NamedCapture module.
1088
1089 Note: "%-" and "%+" are tied views into a common internal hash
1090 associated with the last successful regular expression.
1091 Therefore mixing iterative access to them via "each" may have
1092 unpredictable results. Likewise, if the last successful match
1093 changes, then the results may be surprising.
1094
1095 This variable was added in Perl v5.10.0. The "%{^CAPTURE_ALL}"
1096 alias was added in 5.25.7.
1097
1098 This variable is read-only and dynamically-scoped.
1099
1100 $LAST_REGEXP_CODE_RESULT
1101 $^R The result of evaluation of the last successful "(?{ code })"
1102 regular expression assertion (see perlre). May be written to.
1103
1104 This variable was added in Perl 5.005.
1105
1106 ${^RE_COMPILE_RECURSION_LIMIT}
1107 The current value giving the maximum number of open but
1108 unclosed parenthetical groups there may be at any point during
1109 a regular expression compilation. The default is currently
1110 1000 nested groups. You may adjust it depending on your needs
1111 and the amount of memory available.
1112
1113 This variable was added in Perl v5.30.0.
1114
1115 ${^RE_DEBUG_FLAGS}
1116 The current value of the regex debugging flags. Set to 0 for
1117 no debug output even when the "re 'debug'" module is loaded.
1118 See re for details.
1119
1120 This variable was added in Perl v5.10.0.
1121
1122 ${^RE_TRIE_MAXBUF}
1123 Controls how certain regex optimisations are applied and how
1124 much memory they utilize. This value by default is 65536 which
1125 corresponds to a 512kB temporary cache. Set this to a higher
1126 value to trade memory for speed when matching large
1127 alternations. Set it to a lower value if you want the
1128 optimisations to be as conservative of memory as possible but
1129 still occur, and set it to a negative value to prevent the
1130 optimisation and conserve the most memory. Under normal
1131 situations this variable should be of no interest to you.
1132
1133 This variable was added in Perl v5.10.0.
1134
1135 Variables related to filehandles
1136 Variables that depend on the currently selected filehandle may be set
1137 by calling an appropriate object method on the "IO::Handle" object,
1138 although this is less efficient than using the regular built-in
1139 variables. (Summary lines below for this contain the word HANDLE.)
1140 First you must say
1141
1142 use IO::Handle;
1143
1144 after which you may use either
1145
1146 method HANDLE EXPR
1147
1148 or more safely,
1149
1150 HANDLE->method(EXPR)
1151
1152 Each method returns the old value of the "IO::Handle" attribute. The
1153 methods each take an optional EXPR, which, if supplied, specifies the
1154 new value for the "IO::Handle" attribute in question. If not supplied,
1155 most methods do nothing to the current value--except for "autoflush()",
1156 which will assume a 1 for you, just to be different.
1157
1158 Because loading in the "IO::Handle" class is an expensive operation,
1159 you should learn how to use the regular built-in variables.
1160
1161 A few of these variables are considered "read-only". This means that
1162 if you try to assign to this variable, either directly or indirectly
1163 through a reference, you'll raise a run-time exception.
1164
1165 You should be very careful when modifying the default values of most
1166 special variables described in this document. In most cases you want
1167 to localize these variables before changing them, since if you don't,
1168 the change may affect other modules which rely on the default values of
1169 the special variables that you have changed. This is one of the
1170 correct ways to read the whole file at once:
1171
1172 open my $fh, "<", "foo" or die $!;
1173 local $/; # enable localized slurp mode
1174 my $content = <$fh>;
1175 close $fh;
1176
1177 But the following code is quite bad:
1178
1179 open my $fh, "<", "foo" or die $!;
1180 undef $/; # enable slurp mode
1181 my $content = <$fh>;
1182 close $fh;
1183
1184 since some other module, may want to read data from some file in the
1185 default "line mode", so if the code we have just presented has been
1186 executed, the global value of $/ is now changed for any other code
1187 running inside the same Perl interpreter.
1188
1189 Usually when a variable is localized you want to make sure that this
1190 change affects the shortest scope possible. So unless you are already
1191 inside some short "{}" block, you should create one yourself. For
1192 example:
1193
1194 my $content = '';
1195 open my $fh, "<", "foo" or die $!;
1196 {
1197 local $/;
1198 $content = <$fh>;
1199 }
1200 close $fh;
1201
1202 Here is an example of how your own code can go broken:
1203
1204 for ( 1..3 ){
1205 $\ = "\r\n";
1206 nasty_break();
1207 print "$_";
1208 }
1209
1210 sub nasty_break {
1211 $\ = "\f";
1212 # do something with $_
1213 }
1214
1215 You probably expect this code to print the equivalent of
1216
1217 "1\r\n2\r\n3\r\n"
1218
1219 but instead you get:
1220
1221 "1\f2\f3\f"
1222
1223 Why? Because "nasty_break()" modifies "$\" without localizing it first.
1224 The value you set in "nasty_break()" is still there when you return.
1225 The fix is to add "local()" so the value doesn't leak out of
1226 "nasty_break()":
1227
1228 local $\ = "\f";
1229
1230 It's easy to notice the problem in such a short example, but in more
1231 complicated code you are looking for trouble if you don't localize
1232 changes to the special variables.
1233
1234 $ARGV Contains the name of the current file when reading from "<>".
1235
1236 @ARGV The array @ARGV contains the command-line arguments intended
1237 for the script. $#ARGV is generally the number of arguments
1238 minus one, because $ARGV[0] is the first argument, not the
1239 program's command name itself. See "$0" for the command name.
1240
1241 ARGV The special filehandle that iterates over command-line
1242 filenames in @ARGV. Usually written as the null filehandle in
1243 the angle operator "<>". Note that currently "ARGV" only has
1244 its magical effect within the "<>" operator; elsewhere it is
1245 just a plain filehandle corresponding to the last file opened
1246 by "<>". In particular, passing "\*ARGV" as a parameter to a
1247 function that expects a filehandle may not cause your function
1248 to automatically read the contents of all the files in @ARGV.
1249
1250 ARGVOUT The special filehandle that points to the currently open output
1251 file when doing edit-in-place processing with -i. Useful when
1252 you have to do a lot of inserting and don't want to keep
1253 modifying $_. See perlrun for the -i switch.
1254
1255 IO::Handle->output_field_separator( EXPR )
1256 $OUTPUT_FIELD_SEPARATOR
1257 $OFS
1258 $, The output field separator for the print operator. If defined,
1259 this value is printed between each of print's arguments.
1260 Default is "undef".
1261
1262 You cannot call "output_field_separator()" on a handle, only as
1263 a static method. See IO::Handle.
1264
1265 Mnemonic: what is printed when there is a "," in your print
1266 statement.
1267
1268 HANDLE->input_line_number( EXPR )
1269 $INPUT_LINE_NUMBER
1270 $NR
1271 $. Current line number for the last filehandle accessed.
1272
1273 Each filehandle in Perl counts the number of lines that have
1274 been read from it. (Depending on the value of $/, Perl's idea
1275 of what constitutes a line may not match yours.) When a line
1276 is read from a filehandle (via "readline()" or "<>"), or when
1277 "tell()" or "seek()" is called on it, $. becomes an alias to
1278 the line counter for that filehandle.
1279
1280 You can adjust the counter by assigning to $., but this will
1281 not actually move the seek pointer. Localizing $. will not
1282 localize the filehandle's line count. Instead, it will
1283 localize perl's notion of which filehandle $. is currently
1284 aliased to.
1285
1286 $. is reset when the filehandle is closed, but not when an open
1287 filehandle is reopened without an intervening "close()". For
1288 more details, see "I/O Operators" in perlop. Because "<>"
1289 never does an explicit close, line numbers increase across
1290 "ARGV" files (but see examples in "eof" in perlfunc).
1291
1292 You can also use "HANDLE->input_line_number(EXPR)" to access
1293 the line counter for a given filehandle without having to worry
1294 about which handle you last accessed.
1295
1296 Mnemonic: many programs use "." to mean the current line
1297 number.
1298
1299 IO::Handle->input_record_separator( EXPR )
1300 $INPUT_RECORD_SEPARATOR
1301 $RS
1302 $/ The input record separator, newline by default. This
1303 influences Perl's idea of what a "line" is. Works like awk's
1304 RS variable, including treating empty lines as a terminator if
1305 set to the null string (an empty line cannot contain any spaces
1306 or tabs). You may set it to a multi-character string to match
1307 a multi-character terminator, or to "undef" to read through the
1308 end of file. Setting it to "\n\n" means something slightly
1309 different than setting to "", if the file contains consecutive
1310 empty lines. Setting to "" will treat two or more consecutive
1311 empty lines as a single empty line. Setting to "\n\n" will
1312 blindly assume that the next input character belongs to the
1313 next paragraph, even if it's a newline.
1314
1315 local $/; # enable "slurp" mode
1316 local $_ = <FH>; # whole file now here
1317 s/\n[ \t]+/ /g;
1318
1319 Remember: the value of $/ is a string, not a regex. awk has to
1320 be better for something. :-)
1321
1322 Setting $/ to an empty string -- the so-called paragraph mode
1323 -- merits special attention. When $/ is set to "" and the
1324 entire file is read in with that setting, any sequence of one
1325 or more consecutive newlines at the beginning of the file is
1326 discarded. With the exception of the final record in the file,
1327 each sequence of characters ending in two or more newlines is
1328 treated as one record and is read in to end in exactly two
1329 newlines. If the last record in the file ends in zero or one
1330 consecutive newlines, that record is read in with that number
1331 of newlines. If the last record ends in two or more
1332 consecutive newlines, it is read in with two newlines like all
1333 preceding records.
1334
1335 Suppose we wrote the following string to a file:
1336
1337 my $string = "\n\n\n";
1338 $string .= "alpha beta\ngamma delta\n\n\n";
1339 $string .= "epsilon zeta eta\n\n";
1340 $string .= "theta\n";
1341
1342 my $file = 'simple_file.txt';
1343 open my $OUT, '>', $file or die;
1344 print $OUT $string;
1345 close $OUT or die;
1346
1347 Now we read that file in paragraph mode:
1348
1349 local $/ = ""; # paragraph mode
1350 open my $IN, '<', $file or die;
1351 my @records = <$IN>;
1352 close $IN or die;
1353
1354 @records will consist of these 3 strings:
1355
1356 (
1357 "alpha beta\ngamma delta\n\n",
1358 "epsilon zeta eta\n\n",
1359 "theta\n",
1360 )
1361
1362 Setting $/ to a reference to an integer, scalar containing an
1363 integer, or scalar that's convertible to an integer will
1364 attempt to read records instead of lines, with the maximum
1365 record size being the referenced integer number of characters.
1366 So this:
1367
1368 local $/ = \32768; # or \"32768", or \$var_containing_32768
1369 open my $fh, "<", $myfile or die $!;
1370 local $_ = <$fh>;
1371
1372 will read a record of no more than 32768 characters from $fh.
1373 If you're not reading from a record-oriented file (or your OS
1374 doesn't have record-oriented files), then you'll likely get a
1375 full chunk of data with every read. If a record is larger than
1376 the record size you've set, you'll get the record back in
1377 pieces. Trying to set the record size to zero or less is
1378 deprecated and will cause $/ to have the value of "undef",
1379 which will cause reading in the (rest of the) whole file.
1380
1381 As of 5.19.9 setting $/ to any other form of reference will
1382 throw a fatal exception. This is in preparation for supporting
1383 new ways to set $/ in the future.
1384
1385 On VMS only, record reads bypass PerlIO layers and any
1386 associated buffering, so you must not mix record and non-record
1387 reads on the same filehandle. Record mode mixes with line mode
1388 only when the same buffering layer is in use for both modes.
1389
1390 You cannot call "input_record_separator()" on a handle, only as
1391 a static method. See IO::Handle.
1392
1393 See also "Newlines" in perlport. Also see "$.".
1394
1395 Mnemonic: / delimits line boundaries when quoting poetry.
1396
1397 IO::Handle->output_record_separator( EXPR )
1398 $OUTPUT_RECORD_SEPARATOR
1399 $ORS
1400 $\ The output record separator for the print operator. If
1401 defined, this value is printed after the last of print's
1402 arguments. Default is "undef".
1403
1404 You cannot call "output_record_separator()" on a handle, only
1405 as a static method. See IO::Handle.
1406
1407 Mnemonic: you set "$\" instead of adding "\n" at the end of the
1408 print. Also, it's just like $/, but it's what you get "back"
1409 from Perl.
1410
1411 HANDLE->autoflush( EXPR )
1412 $OUTPUT_AUTOFLUSH
1413 $| If set to nonzero, forces a flush right away and after every
1414 write or print on the currently selected output channel.
1415 Default is 0 (regardless of whether the channel is really
1416 buffered by the system or not; $| tells you only whether you've
1417 asked Perl explicitly to flush after each write). STDOUT will
1418 typically be line buffered if output is to the terminal and
1419 block buffered otherwise. Setting this variable is useful
1420 primarily when you are outputting to a pipe or socket, such as
1421 when you are running a Perl program under rsh and want to see
1422 the output as it's happening. This has no effect on input
1423 buffering. See "getc" in perlfunc for that. See "select" in
1424 perlfunc on how to select the output channel. See also
1425 IO::Handle.
1426
1427 Mnemonic: when you want your pipes to be piping hot.
1428
1429 ${^LAST_FH}
1430 This read-only variable contains a reference to the last-read
1431 filehandle. This is set by "<HANDLE>", "readline", "tell",
1432 "eof" and "seek". This is the same handle that $. and "tell"
1433 and "eof" without arguments use. It is also the handle used
1434 when Perl appends ", <STDIN> line 1" to an error or warning
1435 message.
1436
1437 This variable was added in Perl v5.18.0.
1438
1439 Variables related to formats
1440
1441 The special variables for formats are a subset of those for
1442 filehandles. See perlform for more information about Perl's formats.
1443
1444 $ACCUMULATOR
1445 $^A The current value of the "write()" accumulator for "format()"
1446 lines. A format contains "formline()" calls that put their
1447 result into $^A. After calling its format, "write()" prints
1448 out the contents of $^A and empties. So you never really see
1449 the contents of $^A unless you call "formline()" yourself and
1450 then look at it. See perlform and "formline PICTURE,LIST" in
1451 perlfunc.
1452
1453 IO::Handle->format_formfeed(EXPR)
1454 $FORMAT_FORMFEED
1455 $^L What formats output as a form feed. The default is "\f".
1456
1457 You cannot call "format_formfeed()" on a handle, only as a
1458 static method. See IO::Handle.
1459
1460 HANDLE->format_page_number(EXPR)
1461 $FORMAT_PAGE_NUMBER
1462 $% The current page number of the currently selected output
1463 channel.
1464
1465 Mnemonic: "%" is page number in nroff.
1466
1467 HANDLE->format_lines_left(EXPR)
1468 $FORMAT_LINES_LEFT
1469 $- The number of lines left on the page of the currently selected
1470 output channel.
1471
1472 Mnemonic: lines_on_page - lines_printed.
1473
1474 IO::Handle->format_line_break_characters EXPR
1475 $FORMAT_LINE_BREAK_CHARACTERS
1476 $: The current set of characters after which a string may be
1477 broken to fill continuation fields (starting with "^") in a
1478 format. The default is " \n-", to break on a space, newline,
1479 or a hyphen.
1480
1481 You cannot call "format_line_break_characters()" on a handle,
1482 only as a static method. See IO::Handle.
1483
1484 Mnemonic: a "colon" in poetry is a part of a line.
1485
1486 HANDLE->format_lines_per_page(EXPR)
1487 $FORMAT_LINES_PER_PAGE
1488 $= The current page length (printable lines) of the currently
1489 selected output channel. The default is 60.
1490
1491 Mnemonic: = has horizontal lines.
1492
1493 HANDLE->format_top_name(EXPR)
1494 $FORMAT_TOP_NAME
1495 $^ The name of the current top-of-page format for the currently
1496 selected output channel. The default is the name of the
1497 filehandle with "_TOP" appended. For example, the default
1498 format top name for the "STDOUT" filehandle is "STDOUT_TOP".
1499
1500 Mnemonic: points to top of page.
1501
1502 HANDLE->format_name(EXPR)
1503 $FORMAT_NAME
1504 $~ The name of the current report format for the currently
1505 selected output channel. The default format name is the same
1506 as the filehandle name. For example, the default format name
1507 for the "STDOUT" filehandle is just "STDOUT".
1508
1509 Mnemonic: brother to $^.
1510
1511 Error Variables
1512 The variables $@, $!, $^E, and $? contain information about different
1513 types of error conditions that may appear during execution of a Perl
1514 program. The variables are shown ordered by the "distance" between the
1515 subsystem which reported the error and the Perl process. They
1516 correspond to errors detected by the Perl interpreter, C library,
1517 operating system, or an external program, respectively.
1518
1519 To illustrate the differences between these variables, consider the
1520 following Perl expression, which uses a single-quoted string. After
1521 execution of this statement, perl may have set all four special error
1522 variables:
1523
1524 eval q{
1525 open my $pipe, "/cdrom/install |" or die $!;
1526 my @res = <$pipe>;
1527 close $pipe or die "bad pipe: $?, $!";
1528 };
1529
1530 When perl executes the "eval()" expression, it translates the "open()",
1531 "<PIPE>", and "close" calls in the C run-time library and thence to the
1532 operating system kernel. perl sets $! to the C library's "errno" if
1533 one of these calls fails.
1534
1535 $@ is set if the string to be "eval"-ed did not compile (this may
1536 happen if "open" or "close" were imported with bad prototypes), or if
1537 Perl code executed during evaluation "die()"d. In these cases the
1538 value of $@ is the compile error, or the argument to "die" (which will
1539 interpolate $! and $?). (See also Fatal, though.)
1540
1541 Under a few operating systems, $^E may contain a more verbose error
1542 indicator, such as in this case, "CDROM tray not closed." Systems that
1543 do not support extended error messages leave $^E the same as $!.
1544
1545 Finally, $? may be set to a non-0 value if the external program
1546 /cdrom/install fails. The upper eight bits reflect specific error
1547 conditions encountered by the program (the program's "exit()" value).
1548 The lower eight bits reflect mode of failure, like signal death and
1549 core dump information. See wait(2) for details. In contrast to $! and
1550 $^E, which are set only if an error condition is detected, the variable
1551 $? is set on each "wait" or pipe "close", overwriting the old value.
1552 This is more like $@, which on every "eval()" is always set on failure
1553 and cleared on success.
1554
1555 For more details, see the individual descriptions at $@, $!, $^E, and
1556 $?.
1557
1558 ${^CHILD_ERROR_NATIVE}
1559 The native status returned by the last pipe close, backtick
1560 ("``") command, successful call to "wait()" or "waitpid()", or
1561 from the "system()" operator. On POSIX-like systems this value
1562 can be decoded with the WIFEXITED, WEXITSTATUS, WIFSIGNALED,
1563 WTERMSIG, WIFSTOPPED, and WSTOPSIG functions provided by the
1564 POSIX module.
1565
1566 Under VMS this reflects the actual VMS exit status; i.e. it is
1567 the same as $? when the pragma "use vmsish 'status'" is in
1568 effect.
1569
1570 This variable was added in Perl v5.10.0.
1571
1572 $EXTENDED_OS_ERROR
1573 $^E Error information specific to the current operating system. At
1574 the moment, this differs from "$!" under only VMS, OS/2, and
1575 Win32 (and for MacPerl). On all other platforms, $^E is always
1576 just the same as $!.
1577
1578 Under VMS, $^E provides the VMS status value from the last
1579 system error. This is more specific information about the last
1580 system error than that provided by $!. This is particularly
1581 important when $! is set to EVMSERR.
1582
1583 Under OS/2, $^E is set to the error code of the last call to
1584 OS/2 API either via CRT, or directly from perl.
1585
1586 Under Win32, $^E always returns the last error information
1587 reported by the Win32 call "GetLastError()" which describes the
1588 last error from within the Win32 API. Most Win32-specific code
1589 will report errors via $^E. ANSI C and Unix-like calls set
1590 "errno" and so most portable Perl code will report errors via
1591 $!.
1592
1593 Caveats mentioned in the description of "$!" generally apply to
1594 $^E, also.
1595
1596 This variable was added in Perl 5.003.
1597
1598 Mnemonic: Extra error explanation.
1599
1600 $EXCEPTIONS_BEING_CAUGHT
1601 $^S Current state of the interpreter.
1602
1603 $^S State
1604 --------- -------------------------------------
1605 undef Parsing module, eval, or main program
1606 true (1) Executing an eval
1607 false (0) Otherwise
1608
1609 The first state may happen in $SIG{__DIE__} and $SIG{__WARN__}
1610 handlers.
1611
1612 The English name $EXCEPTIONS_BEING_CAUGHT is slightly
1613 misleading, because the "undef" value does not indicate whether
1614 exceptions are being caught, since compilation of the main
1615 program does not catch exceptions.
1616
1617 This variable was added in Perl 5.004.
1618
1619 $WARNING
1620 $^W The current value of the warning switch, initially true if -w
1621 was used, false otherwise, but directly modifiable.
1622
1623 See also warnings.
1624
1625 Mnemonic: related to the -w switch.
1626
1627 ${^WARNING_BITS}
1628 The current set of warning checks enabled by the "use warnings"
1629 pragma. It has the same scoping as the $^H and "%^H"
1630 variables. The exact values are considered internal to the
1631 warnings pragma and may change between versions of Perl.
1632
1633 This variable was added in Perl v5.6.0.
1634
1635 $OS_ERROR
1636 $ERRNO
1637 $! When referenced, $! retrieves the current value of the C
1638 "errno" integer variable. If $! is assigned a numerical value,
1639 that value is stored in "errno". When referenced as a string,
1640 $! yields the system error string corresponding to "errno".
1641
1642 Many system or library calls set "errno" if they fail, to
1643 indicate the cause of failure. They usually do not set "errno"
1644 to zero if they succeed and may set "errno" to a non-zero value
1645 on success. This means "errno", hence $!, is meaningful only
1646 immediately after a failure:
1647
1648 if (open my $fh, "<", $filename) {
1649 # Here $! is meaningless.
1650 ...
1651 }
1652 else {
1653 # ONLY here is $! meaningful.
1654 ...
1655 # Already here $! might be meaningless.
1656 }
1657 # Since here we might have either success or failure,
1658 # $! is meaningless.
1659
1660 Here, meaningless means that $! may be unrelated to the outcome
1661 of the "open()" operator. Assignment to $! is similarly
1662 ephemeral. It can be used immediately before invoking the
1663 "die()" operator, to set the exit value, or to inspect the
1664 system error string corresponding to error n, or to restore $!
1665 to a meaningful state.
1666
1667 Perl itself may set "errno" to a non-zero on failure even if no
1668 system call is performed.
1669
1670 Mnemonic: What just went bang?
1671
1672 %OS_ERROR
1673 %ERRNO
1674 %! Each element of "%!" has a true value only if $! is set to that
1675 value. For example, $!{ENOENT} is true if and only if the
1676 current value of $! is "ENOENT"; that is, if the most recent
1677 error was "No such file or directory" (or its moral equivalent:
1678 not all operating systems give that exact error, and certainly
1679 not all languages). The specific true value is not guaranteed,
1680 but in the past has generally been the numeric value of $!. To
1681 check if a particular key is meaningful on your system, use
1682 "exists $!{the_key}"; for a list of legal keys, use "keys %!".
1683 See Errno for more information, and also see "$!".
1684
1685 This variable was added in Perl 5.005.
1686
1687 $CHILD_ERROR
1688 $? The status returned by the last pipe close, backtick ("``")
1689 command, successful call to "wait()" or "waitpid()", or from
1690 the "system()" operator. This is just the 16-bit status word
1691 returned by the traditional Unix "wait()" system call (or else
1692 is made up to look like it). Thus, the exit value of the
1693 subprocess is really ("$? >> 8"), and "$? & 127" gives which
1694 signal, if any, the process died from, and "$? & 128" reports
1695 whether there was a core dump.
1696
1697 Additionally, if the "h_errno" variable is supported in C, its
1698 value is returned via $? if any "gethost*()" function fails.
1699
1700 If you have installed a signal handler for "SIGCHLD", the value
1701 of $? will usually be wrong outside that handler.
1702
1703 Inside an "END" subroutine $? contains the value that is going
1704 to be given to "exit()". You can modify $? in an "END"
1705 subroutine to change the exit status of your program. For
1706 example:
1707
1708 END {
1709 $? = 1 if $? == 255; # die would make it 255
1710 }
1711
1712 Under VMS, the pragma "use vmsish 'status'" makes $? reflect
1713 the actual VMS exit status, instead of the default emulation of
1714 POSIX status; see "$?" in perlvms for details.
1715
1716 Mnemonic: similar to sh and ksh.
1717
1718 $EVAL_ERROR
1719 $@ The Perl error from the last "eval" operator, i.e. the last
1720 exception that was caught. For "eval BLOCK", this is either a
1721 runtime error message or the string or reference "die" was
1722 called with. The "eval STRING" form also catches syntax errors
1723 and other compile time exceptions.
1724
1725 If no error occurs, "eval" sets $@ to the empty string.
1726
1727 Warning messages are not collected in this variable. You can,
1728 however, set up a routine to process warnings by setting
1729 $SIG{__WARN__} as described in "%SIG".
1730
1731 Mnemonic: Where was the error "at"?
1732
1733 Variables related to the interpreter state
1734 These variables provide information about the current interpreter
1735 state.
1736
1737 $COMPILING
1738 $^C The current value of the flag associated with the -c switch.
1739 Mainly of use with -MO=... to allow code to alter its behavior
1740 when being compiled, such as for example to "AUTOLOAD" at
1741 compile time rather than normal, deferred loading. Setting
1742 "$^C = 1" is similar to calling "B::minus_c".
1743
1744 This variable was added in Perl v5.6.0.
1745
1746 $DEBUGGING
1747 $^D The current value of the debugging flags. May be read or set.
1748 Like its command-line equivalent, you can use numeric or
1749 symbolic values, e.g. "$^D = 10" or "$^D = "st"". See
1750 "-Dnumber" in perlrun. The contents of this variable also
1751 affects the debugger operation. See "Debugger Internals" in
1752 perldebguts.
1753
1754 Mnemonic: value of -D switch.
1755
1756 ${^ENCODING}
1757 This variable is no longer supported.
1758
1759 It used to hold the object reference to the "Encode" object
1760 that was used to convert the source code to Unicode.
1761
1762 Its purpose was to allow your non-ASCII Perl scripts not to
1763 have to be written in UTF-8; this was useful before editors
1764 that worked on UTF-8 encoded text were common, but that was
1765 long ago. It caused problems, such as affecting the operation
1766 of other modules that weren't expecting it, causing general
1767 mayhem.
1768
1769 If you need something like this functionality, it is
1770 recommended that use you a simple source filter, such as
1771 Filter::Encoding.
1772
1773 If you are coming here because code of yours is being adversely
1774 affected by someone's use of this variable, you can usually
1775 work around it by doing this:
1776
1777 local ${^ENCODING};
1778
1779 near the beginning of the functions that are getting broken.
1780 This undefines the variable during the scope of execution of
1781 the including function.
1782
1783 This variable was added in Perl 5.8.2 and removed in 5.26.0.
1784 Setting it to anything other than "undef" was made fatal in
1785 Perl 5.28.0.
1786
1787 ${^GLOBAL_PHASE}
1788 The current phase of the perl interpreter.
1789
1790 Possible values are:
1791
1792 CONSTRUCT
1793 The "PerlInterpreter*" is being constructed via
1794 "perl_construct". This value is mostly there for
1795 completeness and for use via the underlying C variable
1796 "PL_phase". It's not really possible for Perl code to
1797 be executed unless construction of the interpreter is
1798 finished.
1799
1800 START This is the global compile-time. That includes,
1801 basically, every "BEGIN" block executed directly or
1802 indirectly from during the compile-time of the top-
1803 level program.
1804
1805 This phase is not called "BEGIN" to avoid confusion
1806 with "BEGIN"-blocks, as those are executed during
1807 compile-time of any compilation unit, not just the top-
1808 level program. A new, localised compile-time entered
1809 at run-time, for example by constructs as "eval "use
1810 SomeModule"" are not global interpreter phases, and
1811 therefore aren't reflected by "${^GLOBAL_PHASE}".
1812
1813 CHECK Execution of any "CHECK" blocks.
1814
1815 INIT Similar to "CHECK", but for "INIT"-blocks, not "CHECK"
1816 blocks.
1817
1818 RUN The main run-time, i.e. the execution of
1819 "PL_main_root".
1820
1821 END Execution of any "END" blocks.
1822
1823 DESTRUCT
1824 Global destruction.
1825
1826 Also note that there's no value for UNITCHECK-blocks. That's
1827 because those are run for each compilation unit individually,
1828 and therefore is not a global interpreter phase.
1829
1830 Not every program has to go through each of the possible
1831 phases, but transition from one phase to another can only
1832 happen in the order described in the above list.
1833
1834 An example of all of the phases Perl code can see:
1835
1836 BEGIN { print "compile-time: ${^GLOBAL_PHASE}\n" }
1837
1838 INIT { print "init-time: ${^GLOBAL_PHASE}\n" }
1839
1840 CHECK { print "check-time: ${^GLOBAL_PHASE}\n" }
1841
1842 {
1843 package Print::Phase;
1844
1845 sub new {
1846 my ($class, $time) = @_;
1847 return bless \$time, $class;
1848 }
1849
1850 sub DESTROY {
1851 my $self = shift;
1852 print "$$self: ${^GLOBAL_PHASE}\n";
1853 }
1854 }
1855
1856 print "run-time: ${^GLOBAL_PHASE}\n";
1857
1858 my $runtime = Print::Phase->new(
1859 "lexical variables are garbage collected before END"
1860 );
1861
1862 END { print "end-time: ${^GLOBAL_PHASE}\n" }
1863
1864 our $destruct = Print::Phase->new(
1865 "package variables are garbage collected after END"
1866 );
1867
1868 This will print out
1869
1870 compile-time: START
1871 check-time: CHECK
1872 init-time: INIT
1873 run-time: RUN
1874 lexical variables are garbage collected before END: RUN
1875 end-time: END
1876 package variables are garbage collected after END: DESTRUCT
1877
1878 This variable was added in Perl 5.14.0.
1879
1880 $^H WARNING: This variable is strictly for internal use only. Its
1881 availability, behavior, and contents are subject to change
1882 without notice.
1883
1884 This variable contains compile-time hints for the Perl
1885 interpreter. At the end of compilation of a BLOCK the value of
1886 this variable is restored to the value when the interpreter
1887 started to compile the BLOCK.
1888
1889 When perl begins to parse any block construct that provides a
1890 lexical scope (e.g., eval body, required file, subroutine body,
1891 loop body, or conditional block), the existing value of $^H is
1892 saved, but its value is left unchanged. When the compilation
1893 of the block is completed, it regains the saved value. Between
1894 the points where its value is saved and restored, code that
1895 executes within BEGIN blocks is free to change the value of
1896 $^H.
1897
1898 This behavior provides the semantic of lexical scoping, and is
1899 used in, for instance, the "use strict" pragma.
1900
1901 The contents should be an integer; different bits of it are
1902 used for different pragmatic flags. Here's an example:
1903
1904 sub add_100 { $^H |= 0x100 }
1905
1906 sub foo {
1907 BEGIN { add_100() }
1908 bar->baz($boon);
1909 }
1910
1911 Consider what happens during execution of the BEGIN block. At
1912 this point the BEGIN block has already been compiled, but the
1913 body of "foo()" is still being compiled. The new value of $^H
1914 will therefore be visible only while the body of "foo()" is
1915 being compiled.
1916
1917 Substitution of "BEGIN { add_100() }" block with:
1918
1919 BEGIN { require strict; strict->import('vars') }
1920
1921 demonstrates how "use strict 'vars'" is implemented. Here's a
1922 conditional version of the same lexical pragma:
1923
1924 BEGIN {
1925 require strict; strict->import('vars') if $condition
1926 }
1927
1928 This variable was added in Perl 5.003.
1929
1930 %^H The "%^H" hash provides the same scoping semantic as $^H. This
1931 makes it useful for implementation of lexically scoped pragmas.
1932 See perlpragma. All the entries are stringified when accessed
1933 at runtime, so only simple values can be accommodated. This
1934 means no pointers to objects, for example.
1935
1936 When putting items into "%^H", in order to avoid conflicting
1937 with other users of the hash there is a convention regarding
1938 which keys to use. A module should use only keys that begin
1939 with the module's name (the name of its main package) and a "/"
1940 character. For example, a module "Foo::Bar" should use keys
1941 such as "Foo::Bar/baz".
1942
1943 This variable was added in Perl v5.6.0.
1944
1945 ${^OPEN}
1946 An internal variable used by PerlIO. A string in two parts,
1947 separated by a "\0" byte, the first part describes the input
1948 layers, the second part describes the output layers.
1949
1950 This is the mechanism that applies the lexical effects of the
1951 open pragma, and the main program scope effects of the "io" or
1952 "D" options for the -C command-line switch and PERL_UNICODE
1953 environment variable.
1954
1955 The functions "accept()", "open()", "pipe()", "readpipe()" (as
1956 well as the related "qx" and "`STRING`" operators), "socket()",
1957 "socketpair()", and "sysopen()" are affected by the lexical
1958 value of this variable. The implicit "ARGV" handle opened by
1959 "readline()" (or the related "<>" and "<<>>" operators) on
1960 passed filenames is also affected (but not if it opens
1961 "STDIN"). If this variable is not set, these functions will
1962 set the default layers as described in "Defaults and how to
1963 override them" in PerlIO.
1964
1965 "open()" ignores this variable (and the default layers) when
1966 called with 3 arguments and explicit layers are specified.
1967 Indirect calls to these functions via modules like IO::Handle
1968 are not affected as they occur in a different lexical scope.
1969 Directory handles such as opened by "opendir()" are not
1970 currently affected.
1971
1972 This variable was added in Perl v5.8.0.
1973
1974 $PERLDB
1975 $^P The internal variable for debugging support. The meanings of
1976 the various bits are subject to change, but currently indicate:
1977
1978 0x01 Debug subroutine enter/exit.
1979
1980 0x02 Line-by-line debugging. Causes "DB::DB()" subroutine to
1981 be called for each statement executed. Also causes
1982 saving source code lines (like 0x400).
1983
1984 0x04 Switch off optimizations.
1985
1986 0x08 Preserve more data for future interactive inspections.
1987
1988 0x10 Keep info about source lines on which a subroutine is
1989 defined.
1990
1991 0x20 Start with single-step on.
1992
1993 0x40 Use subroutine address instead of name when reporting.
1994
1995 0x80 Report "goto &subroutine" as well.
1996
1997 0x100 Provide informative "file" names for evals based on the
1998 place they were compiled.
1999
2000 0x200 Provide informative names to anonymous subroutines based
2001 on the place they were compiled.
2002
2003 0x400 Save source code lines into "@{"_<$filename"}".
2004
2005 0x800 When saving source, include evals that generate no
2006 subroutines.
2007
2008 0x1000
2009 When saving source, include source that did not compile.
2010
2011 Some bits may be relevant at compile-time only, some at run-
2012 time only. This is a new mechanism and the details may change.
2013 See also perldebguts.
2014
2015 ${^TAINT}
2016 Reflects if taint mode is on or off. 1 for on (the program was
2017 run with -T), 0 for off, -1 when only taint warnings are
2018 enabled (i.e. with -t or -TU).
2019
2020 This variable is read-only.
2021
2022 This variable was added in Perl v5.8.0.
2023
2024 ${^SAFE_LOCALES}
2025 Reflects if safe locale operations are available to this perl
2026 (when the value is 1) or not (the value is 0). This variable
2027 is always 1 if the perl has been compiled without threads. It
2028 is also 1 if this perl is using thread-safe locale operations.
2029 Note that an individual thread may choose to use the global
2030 locale (generally unsafe) by calling "switch_to_global_locale"
2031 in perlapi. This variable currently is still set to 1 in such
2032 threads.
2033
2034 This variable is read-only.
2035
2036 This variable was added in Perl v5.28.0.
2037
2038 ${^UNICODE}
2039 Reflects certain Unicode settings of Perl. See perlrun
2040 documentation for the "-C" switch for more information about
2041 the possible values.
2042
2043 This variable is set during Perl startup and is thereafter
2044 read-only.
2045
2046 This variable was added in Perl v5.8.2.
2047
2048 ${^UTF8CACHE}
2049 This variable controls the state of the internal UTF-8 offset
2050 caching code. 1 for on (the default), 0 for off, -1 to debug
2051 the caching code by checking all its results against linear
2052 scans, and panicking on any discrepancy.
2053
2054 This variable was added in Perl v5.8.9. It is subject to
2055 change or removal without notice, but is currently used to
2056 avoid recalculating the boundaries of multi-byte UTF-8-encoded
2057 characters.
2058
2059 ${^UTF8LOCALE}
2060 This variable indicates whether a UTF-8 locale was detected by
2061 perl at startup. This information is used by perl when it's in
2062 adjust-utf8ness-to-locale mode (as when run with the "-CL"
2063 command-line switch); see perlrun for more info on this.
2064
2065 This variable was added in Perl v5.8.8.
2066
2067 Deprecated and removed variables
2068 Deprecating a variable announces the intent of the perl maintainers to
2069 eventually remove the variable from the language. It may still be
2070 available despite its status. Using a deprecated variable triggers a
2071 warning.
2072
2073 Once a variable is removed, its use triggers an error telling you the
2074 variable is unsupported.
2075
2076 See perldiag for details about error messages.
2077
2078 $# $# was a variable that could be used to format printed numbers.
2079 After a deprecation cycle, its magic was removed in Perl
2080 v5.10.0 and using it now triggers a warning: "$# is no longer
2081 supported".
2082
2083 This is not the sigil you use in front of an array name to get
2084 the last index, like $#array. That's still how you get the
2085 last index of an array in Perl. The two have nothing to do
2086 with each other.
2087
2088 Deprecated in Perl 5.
2089
2090 Removed in Perl v5.10.0.
2091
2092 $* $* was a variable that you could use to enable multiline
2093 matching. After a deprecation cycle, its magic was removed in
2094 Perl v5.10.0. Using it now triggers a warning: "$* is no
2095 longer supported". You should use the "/s" and "/m" regexp
2096 modifiers instead.
2097
2098 Deprecated in Perl 5.
2099
2100 Removed in Perl v5.10.0.
2101
2102 $[ This variable stores the index of the first element in an
2103 array, and of the first character in a substring. The default
2104 is 0, but you could theoretically set it to 1 to make Perl
2105 behave more like awk (or Fortran) when subscripting and when
2106 evaluating the index() and substr() functions.
2107
2108 As of release 5 of Perl, assignment to $[ is treated as a
2109 compiler directive, and cannot influence the behavior of any
2110 other file. (That's why you can only assign compile-time
2111 constants to it.) Its use is highly discouraged.
2112
2113 Prior to Perl v5.10.0, assignment to $[ could be seen from
2114 outer lexical scopes in the same file, unlike other compile-
2115 time directives (such as strict). Using local() on it would
2116 bind its value strictly to a lexical block. Now it is always
2117 lexically scoped.
2118
2119 As of Perl v5.16.0, it is implemented by the arybase module.
2120
2121 As of Perl v5.30.0, or under "use v5.16", or "no feature
2122 "array_base"", $[ no longer has any effect, and always contains
2123 0. Assigning 0 to it is permitted, but any other value will
2124 produce an error.
2125
2126 Mnemonic: [ begins subscripts.
2127
2128 Deprecated in Perl v5.12.0.
2129
2130
2131
2132perl v5.34.1 2022-03-15 PERLVAR(1)