CINXE.COM

perlvar - Perl predefined variables - Perldoc Browser

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>perlvar - Perl predefined variables - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/perlvar"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/">Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.39.2</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/perlvar">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.0/perlvar">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.2/perlvar">5.38.2</a> <a class="dropdown-item" href="/5.38.1/perlvar">5.38.1</a> <a class="dropdown-item" href="/5.38.0/perlvar">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/perlvar">5.36.3</a> <a class="dropdown-item" href="/5.36.2/perlvar">5.36.2</a> <a class="dropdown-item" href="/5.36.1/perlvar">5.36.1</a> <a class="dropdown-item" href="/5.36.0/perlvar">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/perlvar">5.34.3</a> <a class="dropdown-item" href="/5.34.2/perlvar">5.34.2</a> <a class="dropdown-item" href="/5.34.1/perlvar">5.34.1</a> <a class="dropdown-item" href="/5.34.0/perlvar">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/perlvar">5.32.1</a> <a class="dropdown-item" href="/5.32.0/perlvar">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/perlvar">5.30.3</a> <a class="dropdown-item" href="/5.30.2/perlvar">5.30.2</a> <a class="dropdown-item" href="/5.30.1/perlvar">5.30.1</a> <a class="dropdown-item" href="/5.30.0/perlvar">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/perlvar">5.28.3</a> <a class="dropdown-item" href="/5.28.2/perlvar">5.28.2</a> <a class="dropdown-item" href="/5.28.1/perlvar">5.28.1</a> <a class="dropdown-item" href="/5.28.0/perlvar">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/perlvar">5.26.3</a> <a class="dropdown-item" href="/5.26.2/perlvar">5.26.2</a> <a class="dropdown-item" href="/5.26.1/perlvar">5.26.1</a> <a class="dropdown-item" href="/5.26.0/perlvar">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/perlvar">5.24.4</a> <a class="dropdown-item" href="/5.24.3/perlvar">5.24.3</a> <a class="dropdown-item" href="/5.24.2/perlvar">5.24.2</a> <a class="dropdown-item" href="/5.24.1/perlvar">5.24.1</a> <a class="dropdown-item" href="/5.24.0/perlvar">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/perlvar">5.22.4</a> <a class="dropdown-item" href="/5.22.3/perlvar">5.22.3</a> <a class="dropdown-item" href="/5.22.2/perlvar">5.22.2</a> <a class="dropdown-item" href="/5.22.1/perlvar">5.22.1</a> <a class="dropdown-item" href="/5.22.0/perlvar">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/perlvar">5.20.3</a> <a class="dropdown-item" href="/5.20.2/perlvar">5.20.2</a> <a class="dropdown-item" href="/5.20.1/perlvar">5.20.1</a> <a class="dropdown-item" href="/5.20.0/perlvar">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/perlvar">5.18.4</a> <a class="dropdown-item" href="/5.18.3/perlvar">5.18.3</a> <a class="dropdown-item" href="/5.18.2/perlvar">5.18.2</a> <a class="dropdown-item" href="/5.18.1/perlvar">5.18.1</a> <a class="dropdown-item" href="/5.18.0/perlvar">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/perlvar">5.16.3</a> <a class="dropdown-item" href="/5.16.2/perlvar">5.16.2</a> <a class="dropdown-item" href="/5.16.1/perlvar">5.16.1</a> <a class="dropdown-item" href="/5.16.0/perlvar">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/perlvar">5.14.4</a> <a class="dropdown-item" href="/5.14.3/perlvar">5.14.3</a> <a class="dropdown-item" href="/5.14.2/perlvar">5.14.2</a> <a class="dropdown-item" href="/5.14.1/perlvar">5.14.1</a> <a class="dropdown-item" href="/5.14.0/perlvar">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/perlvar">5.12.5</a> <a class="dropdown-item" href="/5.12.4/perlvar">5.12.4</a> <a class="dropdown-item" href="/5.12.3/perlvar">5.12.3</a> <a class="dropdown-item" href="/5.12.2/perlvar">5.12.2</a> <a class="dropdown-item" href="/5.12.1/perlvar">5.12.1</a> <a class="dropdown-item" href="/5.12.0/perlvar">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/perlvar">5.10.1</a> <a class="dropdown-item" href="/5.10.0/perlvar">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/perlvar">5.8.9</a> <a class="dropdown-item" href="/5.8.8/perlvar">5.8.8</a> <a class="dropdown-item" href="/5.8.7/perlvar">5.8.7</a> <a class="dropdown-item" href="/5.8.6/perlvar">5.8.6</a> <a class="dropdown-item" href="/5.8.5/perlvar">5.8.5</a> <a class="dropdown-item" href="/5.8.4/perlvar">5.8.4</a> <a class="dropdown-item" href="/5.8.3/perlvar">5.8.3</a> <a class="dropdown-item" href="/5.8.2/perlvar">5.8.2</a> <a class="dropdown-item" href="/5.8.1/perlvar">5.8.1</a> <a class="dropdown-item" href="/5.8.0/perlvar">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/perlvar">5.6.2</a> <a class="dropdown-item" href="/5.6.1/perlvar">5.6.1</a> <a class="dropdown-item" href="/5.6.0/perlvar">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/perlvar">5.005_04</a> <a class="dropdown-item" href="/5.005_03/perlvar">5.005_03</a> <a class="dropdown-item" href="/5.005_02/perlvar">5.005_02</a> <a class="dropdown-item" href="/5.005_01/perlvar">5.005_01</a> <a class="dropdown-item" href="/5.005/perlvar">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/perlvar">blead</a> <a class="dropdown-item" href="/5.41.6/perlvar">5.41.6</a> <a class="dropdown-item" href="/5.41.5/perlvar">5.41.5</a> <a class="dropdown-item" href="/5.41.4/perlvar">5.41.4</a> <a class="dropdown-item" href="/5.41.3/perlvar">5.41.3</a> <a class="dropdown-item" href="/5.41.2/perlvar">5.41.2</a> <a class="dropdown-item" href="/5.41.1/perlvar">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.0-RC2/perlvar">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/perlvar">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/perlvar">5.39.10</a> <a class="dropdown-item" href="/5.39.9/perlvar">5.39.9</a> <a class="dropdown-item" href="/5.39.8/perlvar">5.39.8</a> <a class="dropdown-item" href="/5.39.7/perlvar">5.39.7</a> <a class="dropdown-item" href="/5.39.6/perlvar">5.39.6</a> <a class="dropdown-item" href="/5.39.5/perlvar">5.39.5</a> <a class="dropdown-item" href="/5.39.4/perlvar">5.39.4</a> <a class="dropdown-item" href="/5.39.3/perlvar">5.39.3</a> <a class="dropdown-item active" href="/5.39.2/perlvar">5.39.2</a> <a class="dropdown-item" href="/5.39.1/perlvar">5.39.1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.39.2/perl">Perl</a> <a class="dropdown-item" href="/5.39.2/perlintro">Intro</a> <a class="dropdown-item" href="/5.39.2/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.39.2/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.39.2/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.2/perlop">Operators</a> <a class="dropdown-item" href="/5.39.2/functions">Functions</a> <a class="dropdown-item" href="/5.39.2/variables">Variables</a> <a class="dropdown-item" href="/5.39.2/modules">Modules</a> <a class="dropdown-item" href="/5.39.2/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.2/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.39.2/perlcommunity">Community</a> <a class="dropdown-item" href="/5.39.2/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.39.2/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.39.2/perlvar">perlvar</a> <div id="more"> (<a href="/5.39.2/perlvar.txt">source</a>, <a href="https://metacpan.org/pod/perlvar">CPAN</a>) </div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.39.2. This is a development version of Perl. </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> <ul> <li> <a class="text-decoration-none" href="#The-Syntax-of-Variable-Names">The Syntax of Variable Names</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#SPECIAL-VARIABLES">SPECIAL VARIABLES</a> <ul> <li> <a class="text-decoration-none" href="#General-Variables">General Variables</a> </li> <li> <a class="text-decoration-none" href="#Variables-related-to-regular-expressions">Variables related to regular expressions</a> <ul> <li> <a class="text-decoration-none" href="#Scoping-Rules-of-Regex-Variables">Scoping Rules of Regex Variables</a> </li> <li> <a class="text-decoration-none" href="#Performance-issues">Performance issues</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#Variables-related-to-filehandles">Variables related to filehandles</a> <ul> <li> <a class="text-decoration-none" href="#Variables-related-to-formats">Variables related to formats</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#Error-Variables">Error Variables </a> </li> <li> <a class="text-decoration-none" href="#Variables-related-to-the-interpreter-state">Variables related to the interpreter state</a> </li> <li> <a class="text-decoration-none" href="#Deprecated-and-removed-variables">Deprecated and removed variables</a> </li> </ul> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>perlvar - Perl predefined variables</p> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <h2 id="The-Syntax-of-Variable-Names"><a class="permalink" href="#The-Syntax-of-Variable-Names">#</a><a id="The"></a>The Syntax of Variable Names</h2> <p>Variable names in Perl can have several formats. Usually, they must begin with a letter or underscore, in which case they can be arbitrarily long (up to an internal limit of 251 characters) and may contain letters, digits, underscores, or the special sequence <code>::</code> or <code>&#39;</code>. In this case, the part before the last <code>::</code> or <code>&#39;</code> is taken to be a <i>package qualifier</i>; see <a href="/5.39.2/perlmod">perlmod</a>. A Unicode letter that is not ASCII is not considered to be a letter unless <span style="white-space: nowrap;"><code>&quot;use utf8&quot;</code></span> is in effect, and somewhat more complicated rules apply; see <a href="/5.39.2/perldata#Identifier-parsing">&quot;Identifier parsing&quot; in perldata</a> for details.</p> <p>Perl variable names may also be a sequence of digits, a single punctuation character, or the two-character sequence: <code>^</code> (caret or CIRCUMFLEX ACCENT) followed by any one of the characters <code>[][A-Z^_?\]</code>. These names are all reserved for special uses by Perl; for example, the all-digits names are used to hold data captured by backreferences after a regular expression match.</p> <p>Since Perl v5.6.0, Perl variable names may also be alphanumeric strings preceded by a caret. These must all be written using the demarcated variable form using curly braces such as <code>${^Foo}</code>; the braces are <b>not</b> optional. <code>${^Foo}</code> denotes the scalar variable whose name is considered to be a control-<code>F</code> followed by two <code>o</code>&#39;s. (See <a href="/5.39.2/perldata#Demarcated-variable-names-using-braces">&quot;Demarcated variable names using braces&quot; in perldata</a> for more information on this form of spelling a variable name or specifying access to an element of an array or a hash). These variables are reserved for future special uses by Perl, except for the ones that begin with <code>^_</code> (caret-underscore). No name that begins with <code>^_</code> will acquire a special meaning in any future version of Perl; such names may therefore be used safely in programs. <code>$^_</code> itself, however, <i>is</i> reserved.</p> <p>Note that you also <b>must</b> use the demarcated form to access subscripts of variables of this type when interpolating, for instance to access the first element of the <code>@{^CAPTURE}</code> variable inside of a double quoted string you would write <code>&quot;${^CAPTURE[0]}&quot;</code> and NOT <code>&quot;${^CAPTURE}[0]&quot;</code> which would mean to reference a scalar variable named <code>${^CAPTURE}</code> and not index 0 of the magic <code>@{^CAPTURE}</code> array which is populated by the regex engine.</p> <p>Perl identifiers that begin with digits or punctuation characters are exempt from the effects of the <code>package</code> declaration and are always forced to be in package <code>main</code>; they are also exempt from <code>strict &#39;vars&#39;</code> errors. A few other names are also exempt in these ways:</p> <pre><code class="plaintext">ENV STDIN INC STDOUT ARGV STDERR ARGVOUT SIG</code></pre> <p>In particular, the special <code>${^_XYZ}</code> variables are always taken to be in package <code>main</code>, regardless of any <code>package</code> declarations presently in scope.</p> <h1 id="SPECIAL-VARIABLES"><a class="permalink" href="#SPECIAL-VARIABLES">#</a><a id="SPECIAL"></a>SPECIAL VARIABLES</h1> <p>The following names have special meaning to Perl. Most punctuation names have reasonable mnemonics, or analogs in the shells. Nevertheless, if you wish to use long variable names, you need only say:</p> <pre><code>use English;</code></pre> <p>at the top of your program. This aliases all the short names to the long names in the current package. Some even have medium names, generally borrowed from <b>awk</b>. For more info, please see <a href="/5.39.2/English">English</a>.</p> <p>Before you continue, note the sort order for variables. In general, we first list the variables in case-insensitive, almost-lexigraphical order (ignoring the <code>{</code> or <code>^</code> preceding words, as in <code>${^UNICODE}</code> or <code>$^T</code>), although <code>$_</code> and <code>@_</code> move up to the top of the pile. For variables with the same identifier, we list it in order of scalar, array, hash, and bareword.</p> <h2 id="General-Variables"><a class="permalink" href="#General-Variables">#</a><a id="General"></a>General Variables</h2> <dl> <dt id="$ARG"><a class="permalink" href="#$ARG">#</a><a id="ARG"></a>$ARG</dt> <dd> </dd> <dt id="$_"><a class="permalink" href="#$_">#</a><a id="pod-_"></a>$_ </dt> <dd> <p>The default input and pattern-searching space. The following pairs are equivalent:</p> <pre><code>while (&lt;&gt;) {...} # equivalent only in while! while (defined($_ = &lt;&gt;)) {...} /^Subject:/ $_ =~ /^Subject:/ tr/a-z/A-Z/ $_ =~ tr/a-z/A-Z/ chomp chomp($_)</code></pre> <p>Here are the places where Perl will assume <code>$_</code> even if you don&#39;t use it:</p> <ul> <li><p>The following functions use <code>$_</code> as a default argument:</p> <p>abs, alarm, chomp, chop, chr, chroot, cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only), rmdir, say, sin, split (for its second argument), sqrt, stat, study, uc, ucfirst, unlink, unpack.</p> </li> <li><p>All file tests (<code>-f</code>, <code>-d</code>) except for <code>-t</code>, which defaults to STDIN. See <a href="/5.39.2/perlfunc#-X">&quot;-X&quot; in perlfunc</a></p> </li> <li><p>The pattern matching operations <code>m//</code>, <code>s///</code> and <code>tr///</code> (aka <code>y///</code>) when used without an <code>=~</code> operator.</p> </li> <li><p>The default iterator variable in a <code>foreach</code> loop if no other variable is supplied.</p> </li> <li><p>The implicit iterator variable in the <code>grep()</code> and <code>map()</code> functions.</p> </li> <li><p>The implicit variable of <code>given()</code>.</p> </li> <li><p>The default place to put the next value or input record when a <code>&lt;FH&gt;</code>, <code>readline</code>, <code>readdir</code> or <code>each</code> operation&#39;s result is tested by itself as the sole criterion of a <code>while</code> test. Outside a <code>while</code> test, this will not happen.</p> </li> </ul> <p><code>$_</code> is a global variable.</p> <p>However, between perl v5.10.0 and v5.24.0, it could be used lexically by writing <code>my $_</code>. Making <code>$_</code> refer to the global <code>$_</code> in the same scope was then possible with <code>our $_</code>. This experimental feature was removed and is now a fatal error, but you may encounter it in older code.</p> <p>Mnemonic: underline is understood in certain operations.</p> </dd> <dt id="@ARG"><a class="permalink" href="#@ARG">#</a><a id="ARG1"></a>@ARG</dt> <dd> </dd> <dt id="@_"><a class="permalink" href="#@_">#</a><a id="pod-_1"></a>@_ </dt> <dd> <p>Within a subroutine the array <code>@_</code> contains the parameters passed to that subroutine. Inside a subroutine, <code>@_</code> is the default array for the array operators <code>pop</code> and <code>shift</code>.</p> <p>See <a href="/5.39.2/perlsub">perlsub</a>.</p> </dd> <dt id="$LIST_SEPARATOR"><a class="permalink" href="#$LIST_SEPARATOR">#</a><a id="LIST_SEPARATOR"></a>$LIST_SEPARATOR</dt> <dd> </dd> <dt id="$&quot;"><a class="permalink" href="#$%22">#</a><a id="pod"></a>$&quot; </dt> <dd> <p>When an array or an array slice is interpolated into a double-quoted string or a similar context such as <code>/.../</code>, its elements are separated by this value. Default is a space. For example, this:</p> <pre><code>print &quot;The array is: @array\n&quot;;</code></pre> <p>is equivalent to this:</p> <pre><code>print &quot;The array is: &quot; . join($&quot;, @array) . &quot;\n&quot;;</code></pre> <p>Mnemonic: works in double-quoted context.</p> </dd> <dt id="$PROCESS_ID"><a class="permalink" href="#$PROCESS_ID">#</a><a id="PROCESS_ID"></a>$PROCESS_ID</dt> <dd> </dd> <dt id="$PID"><a class="permalink" href="#$PID">#</a><a id="PID"></a>$PID</dt> <dd> </dd> <dt id="$$"><a class="permalink" href="#$$">#</a><a id="pod1"></a>$$ </dt> <dd> <p>The process number of the Perl running this script. Though you <i>can</i> set this variable, doing so is generally discouraged, although it can be invaluable for some testing purposes. It will be reset automatically across <code>fork()</code> calls.</p> <p>Note for Linux and Debian GNU/kFreeBSD users: Before Perl v5.16.0 perl would emulate POSIX semantics on Linux systems using LinuxThreads, a partial implementation of POSIX Threads that has since been superseded by the Native POSIX Thread Library (NPTL).</p> <p>LinuxThreads is now obsolete on Linux, and caching <code>getpid()</code> like this made embedding perl unnecessarily complex (since you&#39;d have to manually update the value of $$), so now <code>$$</code> and <code>getppid()</code> will always return the same values as the underlying C library.</p> <p>Debian GNU/kFreeBSD systems also used LinuxThreads up until and including the 6.0 release, but after that moved to FreeBSD thread semantics, which are POSIX-like.</p> <p>To see if your system is affected by this discrepancy check if <code>getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL</code> returns a false value. NTPL threads preserve the POSIX semantics.</p> <p>Mnemonic: same as shells.</p> </dd> <dt id="$PROGRAM_NAME"><a class="permalink" href="#$PROGRAM_NAME">#</a><a id="PROGRAM_NAME"></a>$PROGRAM_NAME</dt> <dd> </dd> <dt id="$0"><a class="permalink" href="#$0">#</a><a id="pod-0"></a>$0 </dt> <dd> <p>Contains the name of the program being executed.</p> <p>On some (but not all) operating systems assigning to <code>$0</code> modifies the argument area that the <code>ps</code> program sees. On some platforms you may have to use special <code>ps</code> options or a different <code>ps</code> to see the changes. Modifying the <code>$0</code> is more useful as a way of indicating the current program state than it is for hiding the program you&#39;re running.</p> <p>Note that there are platform-specific limitations on the maximum length of <code>$0</code>. In the most extreme case it may be limited to the space occupied by the original <code>$0</code>.</p> <p>In some platforms there may be arbitrary amount of padding, for example space characters, after the modified name as shown by <code>ps</code>. In some platforms this padding may extend all the way to the original length of the argument area, no matter what you do (this is the case for example with Linux 2.2).</p> <p>Note for BSD users: setting <code>$0</code> does not completely remove &quot;perl&quot; from the ps(1) output. For example, setting <code>$0</code> to <code>&quot;foobar&quot;</code> may result in <code>&quot;perl: foobar (perl)&quot;</code> (whether both the <code>&quot;perl: &quot;</code> prefix and the &quot; (perl)&quot; suffix are shown depends on your exact BSD variant and version). This is an operating system feature, Perl cannot help it.</p> <p>In multithreaded scripts Perl coordinates the threads so that any thread may modify its copy of the <code>$0</code> and the change becomes visible to ps(1) (assuming the operating system plays along). Note that the view of <code>$0</code> the other threads have will not change since they have their own copies of it.</p> <p>If the program has been given to perl via the switches <code>-e</code> or <code>-E</code>, <code>$0</code> will contain the string <code>&quot;-e&quot;</code>.</p> <p>On Linux as of perl v5.14.0 the legacy process name will be set with <code>prctl(2)</code>, in addition to altering the POSIX name via <code>argv[0]</code> as perl has done since version 4.000. Now system utilities that read the legacy process name such as ps, top and killall will recognize the name you set when assigning to <code>$0</code>. The string you supply will be cut off at 16 bytes, this is a limitation imposed by Linux.</p> <p>Wide characters are invalid in <code>$0</code> values. For historical reasons, though, Perl accepts them and encodes them to UTF-8. When this happens a wide-character warning is triggered.</p> <p>Mnemonic: same as <b>sh</b> and <b>ksh</b>.</p> </dd> <dt id="$REAL_GROUP_ID"><a class="permalink" href="#$REAL_GROUP_ID">#</a><a id="REAL_GROUP_ID"></a>$REAL_GROUP_ID</dt> <dd> </dd> <dt id="$GID"><a class="permalink" href="#$GID">#</a><a id="GID"></a>$GID</dt> <dd> </dd> <dt id="$("><a class="permalink" href="#$(">#</a><a id="pod2"></a>$( </dt> <dd> <p>The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by <code>getgid()</code>, and the subsequent ones by <code>getgroups()</code>, one of which may be the same as the first number.</p> <p>However, a value assigned to <code>$(</code> must be a single number used to set the real gid. So the value given by <code>$(</code> should <i>not</i> be assigned back to <code>$(</code> without being forced numeric, such as by adding zero. Note that this is different to the effective gid (<code>$)</code>) which does take a list.</p> <p>You can change both the real gid and the effective gid at the same time by using <code>POSIX::setgid()</code>. Changes to <code>$(</code> require a check to <code>$!</code> to detect any possible errors after an attempted change.</p> <p>Mnemonic: parentheses are used to <i>group</i> things. The real gid is the group you <i>left</i>, if you&#39;re running setgid.</p> </dd> <dt id="$EFFECTIVE_GROUP_ID"><a class="permalink" href="#$EFFECTIVE_GROUP_ID">#</a><a id="EFFECTIVE_GROUP_ID"></a>$EFFECTIVE_GROUP_ID</dt> <dd> </dd> <dt id="$EGID"><a class="permalink" href="#$EGID">#</a><a id="EGID"></a>$EGID</dt> <dd> </dd> <dt id="$)"><a class="permalink" href="#$)">#</a><a id="pod3"></a>$) </dt> <dd> <p>The effective gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by <code>getegid()</code>, and the subsequent ones by <code>getgroups()</code>, one of which may be the same as the first number.</p> <p>Similarly, a value assigned to <code>$)</code> must also be a space-separated list of numbers. The first number sets the effective gid, and the rest (if any) are passed to <code>setgroups()</code>. To get the effect of an empty list for <code>setgroups()</code>, just repeat the new effective gid; that is, to force an effective gid of 5 and an effectively empty <code>setgroups()</code> list, say <code> $) = &quot;5 5&quot; </code>.</p> <p>You can change both the effective gid and the real gid at the same time by using <code>POSIX::setgid()</code> (use only a single numeric argument). Changes to <code>$)</code> require a check to <code>$!</code> to detect any possible errors after an attempted change.</p> <p><code>$&lt;</code>, <code>$&gt;</code>, <code>$(</code> and <code>$)</code> can be set only on machines that support the corresponding <i>set[re][ug]id()</i> routine. <code>$(</code> and <code>$)</code> can be swapped only on machines supporting <code>setregid()</code>.</p> <p>Mnemonic: parentheses are used to <i>group</i> things. The effective gid is the group that&#39;s <i>right</i> for you, if you&#39;re running setgid.</p> </dd> <dt id="$REAL_USER_ID"><a class="permalink" href="#$REAL_USER_ID">#</a><a id="REAL_USER_ID"></a>$REAL_USER_ID</dt> <dd> </dd> <dt id="$UID"><a class="permalink" href="#$UID">#</a><a id="UID"></a>$UID</dt> <dd> </dd> <dt id="$&lt;"><a class="permalink" href="#$%3C">#</a><a id="pod4"></a>$&lt; </dt> <dd> <p>The real uid of this process. You can change both the real uid and the effective uid at the same time by using <code>POSIX::setuid()</code>. Since changes to <code>$&lt;</code> require a system call, check <code>$!</code> after a change attempt to detect any possible errors.</p> <p>Mnemonic: it&#39;s the uid you came <i>from</i>, if you&#39;re running setuid.</p> </dd> <dt id="$EFFECTIVE_USER_ID"><a class="permalink" href="#$EFFECTIVE_USER_ID">#</a><a id="EFFECTIVE_USER_ID"></a>$EFFECTIVE_USER_ID</dt> <dd> </dd> <dt id="$EUID"><a class="permalink" href="#$EUID">#</a><a id="EUID"></a>$EUID</dt> <dd> </dd> <dt id="$&gt;"><a class="permalink" href="#$%3E">#</a><a id="pod5"></a>$&gt; </dt> <dd> <p>The effective uid of this process. For example:</p> <pre><code>$&lt; = $&gt;; # set real to effective uid ($&lt;,$&gt;) = ($&gt;,$&lt;); # swap real and effective uids</code></pre> <p>You can change both the effective uid and the real uid at the same time by using <code>POSIX::setuid()</code>. Changes to <code>$&gt;</code> require a check to <code>$!</code> to detect any possible errors after an attempted change.</p> <p><code>$&lt;</code> and <code>$&gt;</code> can be swapped only on machines supporting <code>setreuid()</code>.</p> <p>Mnemonic: it&#39;s the uid you went <i>to</i>, if you&#39;re running setuid.</p> </dd> <dt id="$SUBSCRIPT_SEPARATOR"><a class="permalink" href="#$SUBSCRIPT_SEPARATOR">#</a><a id="SUBSCRIPT_SEPARATOR"></a>$SUBSCRIPT_SEPARATOR</dt> <dd> </dd> <dt id="$SUBSEP"><a class="permalink" href="#$SUBSEP">#</a><a id="SUBSEP"></a>$SUBSEP</dt> <dd> </dd> <dt id="$;"><a class="permalink" href="#$;">#</a><a id="pod6"></a>$; </dt> <dd> <p>The subscript separator for multidimensional array emulation. If you refer to a hash element as</p> <pre><code>$foo{$x,$y,$z}</code></pre> <p>it really means</p> <pre><code>$foo{join($;, $x, $y, $z)}</code></pre> <p>But don&#39;t put</p> <pre><code>@foo{$x,$y,$z} # a slice--note the @</code></pre> <p>which means</p> <pre><code>($foo{$x},$foo{$y},$foo{$z})</code></pre> <p>Default is &quot;\034&quot;, the same as SUBSEP in <b>awk</b>. If your keys contain binary data there might not be any safe value for <code>$;</code>.</p> <p>Consider using &quot;real&quot; multidimensional arrays as described in <a href="/5.39.2/perllol">perllol</a>.</p> <p>Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon.</p> </dd> <dt id="$a"><a class="permalink" href="#$a">#</a><a id="a"></a>$a</dt> <dd> </dd> <dt id="$b"><a class="permalink" href="#$b">#</a><a id="b"></a>$b </dt> <dd> <p>Special package variables when using <code>sort()</code>, see <a href="/5.39.2/perlfunc#sort">&quot;sort&quot; in perlfunc</a>. Because of this specialness <code>$a</code> and <code>$b</code> don&#39;t need to be declared (using <code>use vars</code>, or <code>our()</code>) even when using the <code>strict &#39;vars&#39;</code> pragma. Don&#39;t lexicalize them with <code>my $a</code> or <code>my $b</code> if you want to be able to use them in the <code>sort()</code> comparison block or function.</p> </dd> <dt id="%ENV"><a class="permalink" href="#%25ENV">#</a><a id="ENV"></a>%ENV </dt> <dd> <p>The hash <code>%ENV</code> contains your current environment. Setting a value in <code>ENV</code> changes the environment for any child processes you subsequently <code>fork()</code> off.</p> <p>As of v5.18.0, both keys and values stored in <code>%ENV</code> are stringified.</p> <pre><code>my $foo = 1; $ENV{&#39;bar&#39;} = \$foo; if( ref $ENV{&#39;bar&#39;} ) { say &quot;Pre 5.18.0 Behaviour&quot;; } else { say &quot;Post 5.18.0 Behaviour&quot;; }</code></pre> <p>Previously, only child processes received stringified values:</p> <pre><code>my $foo = 1; $ENV{&#39;bar&#39;} = \$foo; # Always printed &#39;non ref&#39; system($^X, &#39;-e&#39;, q/print ( ref $ENV{&#39;bar&#39;} ? &#39;ref&#39; : &#39;non ref&#39; ) /);</code></pre> <p>This happens because you can&#39;t really share arbitrary data structures with foreign processes.</p> </dd> <dt id="$OLD_PERL_VERSION"><a class="permalink" href="#$OLD_PERL_VERSION">#</a><a id="OLD_PERL_VERSION"></a>$OLD_PERL_VERSION</dt> <dd> </dd> <dt id="$]"><a class="permalink" href="#$%5D">#</a><a id="pod7"></a>$] </dt> <dd> <p>The revision, version, and subversion of the Perl interpreter, represented as a decimal of the form 5.XXXYYY, where XXX is the version / 1e3 and YYY is the subversion / 1e6. For example, Perl v5.10.1 would be &quot;5.010001&quot;.</p> <p>This variable can be used to determine whether the Perl interpreter executing a script is in the right range of versions:</p> <pre><code>warn &quot;No PerlIO!\n&quot; if &quot;$]&quot; &lt; 5.008;</code></pre> <p>When comparing <code>$]</code>, numeric comparison operators should be used, but the variable should be stringified first to avoid issues where its original numeric value is inaccurate.</p> <p>See also the documentation of <a href="/5.39.2/perlfunc#use-VERSION"><code>use VERSION</code></a> and <code>require VERSION</code> for a convenient way to fail if the running Perl interpreter is too old.</p> <p>See <a href="#%24%5EV">&quot;$^V&quot;</a> for a representation of the Perl version as a <a href="/5.39.2/version">version</a> object, which allows more flexible string comparisons.</p> <p>The main advantage of <code>$]</code> over <code>$^V</code> is that it works the same on any version of Perl. The disadvantages are that it can&#39;t easily be compared to versions in other formats (e.g. literal v-strings, &quot;v1.2.3&quot; or version objects) and numeric comparisons are subject to the binary floating point representation; it&#39;s good for numeric literal version checks and bad for comparing to a variable that hasn&#39;t been sanity-checked.</p> <p>The <code>$OLD_PERL_VERSION</code> form was added in Perl v5.20.0 for historical reasons but its use is discouraged. (If your reason to use <code>$]</code> is to run code on old perls then referring to it as <code>$OLD_PERL_VERSION</code> would be self-defeating.)</p> <p>Mnemonic: Is this version of perl in the right bracket?</p> </dd> <dt id="$SYSTEM_FD_MAX"><a class="permalink" href="#$SYSTEM_FD_MAX">#</a><a id="SYSTEM_FD_MAX"></a>$SYSTEM_FD_MAX</dt> <dd> </dd> <dt id="$^F"><a class="permalink" href="#$%5EF">#</a><a id="F"></a>$^F </dt> <dd> <p>The maximum system file descriptor, ordinarily 2. System file descriptors are passed to <code>exec()</code>ed processes, while higher file descriptors are not. Also, during an <code>open()</code>, system file descriptors are preserved even if the <code>open()</code> fails (ordinary file descriptors are closed before the <code>open()</code> is attempted). The close-on-exec status of a file descriptor will be decided according to the value of <code>$^F</code> when the corresponding file, pipe, or socket was opened, not the time of the <code>exec()</code>.</p> </dd> <dt id="@F"><a class="permalink" href="#@F">#</a><a id="F1"></a>@F </dt> <dd> <p>The array <code>@F</code> contains the fields of each line read in when autosplit mode is turned on. See <a href="/5.39.2/perlrun#-a">perlrun</a> for the <b>-a</b> switch. This array is package-specific, and must be declared or given a full package name if not in package main when running under <code>strict &#39;vars&#39;</code>.</p> </dd> <dt id="@INC"><a class="permalink" href="#@INC">#</a><a id="INC"></a>@INC </dt> <dd> <p>The array <code>@INC</code> contains the list of places that the <code>do EXPR</code>, <code>require</code>, or <code>use</code> constructs look for their library files. It initially consists of the arguments to any <b>-I</b> command-line switches, followed by the default Perl library, probably <i>/usr/local/lib/perl</i>. Prior to Perl 5.26, <code>.</code> -which represents the current directory, was included in <code>@INC</code>; it has been removed. This change in behavior is documented in <a href="/5.39.2/perlrun#PERL_USE_UNSAFE_INC"><code>PERL_USE_UNSAFE_INC</code></a> and it is not recommended that <code>.</code> be re-added to <code>@INC</code>. If you need to modify <code>@INC</code> at runtime, you should use the <code>use lib</code> pragma to get the machine-dependent library properly loaded as well:</p> <pre><code>use lib &#39;/mypath/libdir/&#39;; use SomeMod;</code></pre> <p>You can also insert hooks into the file inclusion system by putting Perl code directly into <code>@INC</code>. Those hooks may be subroutine references, array references or blessed objects. See <a href="/5.39.2/perlfunc#require">&quot;require&quot; in perlfunc</a> for details.</p> </dd> <dt id="%INC"><a class="permalink" href="#%25INC">#</a><a id="INC1"></a>%INC </dt> <dd> <p>The hash <code>%INC</code> contains entries for each filename included via the <code>do</code>, <code>require</code>, or <code>use</code> operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found. The <code>require</code> operator uses this hash to determine whether a particular file has already been included.</p> <p>If the file was loaded via a hook (e.g. a subroutine reference, see <a href="/5.39.2/perlfunc#require">&quot;require&quot; in perlfunc</a> for a description of these hooks), this hook is by default inserted into <code>%INC</code> in place of a filename. Note, however, that the hook may have set the <code>%INC</code> entry by itself to provide some more specific info.</p> </dd> <dt id="$INC"><a class="permalink" href="#$INC">#</a><a id="INC2"></a>$INC </dt> <dd> <p>As of 5.37.7 when an <code>@INC</code> hook is executed the index of the <code>@INC</code> array that holds the hook will be localized into the <code>$INC</code> variable. When the hook returns the integer successor of its value will be used to determine the next index in <code>@INC</code> that will be checked, thus if it is set to -1 (or <code>undef</code>) the traversal over the <code>@INC</code> array will be restarted from its beginning.</p> <p>Normally traversal through the <code>@INC</code> array is from beginning to end (<code>0 .. $#INC</code>), and if the <code>@INC</code> array is modified by the hook the iterator may be left in a state where newly added entries are skipped. Changing this value allows an <code>@INC</code> hook to rewrite the <code>@INC</code> array and tell Perl where to continue afterwards. See <a href="/5.39.2/perlfunc#require">&quot;require&quot; in perlfunc</a> for details on <code>@INC</code> hooks.</p> </dd> <dt id="$INPLACE_EDIT"><a class="permalink" href="#$INPLACE_EDIT">#</a><a id="INPLACE_EDIT"></a>$INPLACE_EDIT</dt> <dd> </dd> <dt id="$^I"><a class="permalink" href="#$%5EI">#</a><a id="I"></a>$^I </dt> <dd> <p>The current value of the inplace-edit extension. Use <code>undef</code> to disable inplace editing.</p> <p>Mnemonic: value of <b>-i</b> switch.</p> </dd> <dt id="@ISA"><a class="permalink" href="#@ISA">#</a><a id="ISA"></a>@ISA </dt> <dd> <p>Each package contains a special array called <code>@ISA</code> which contains a list of that class&#39;s parent classes, if any. This array is simply a list of scalars, each of which is a string that corresponds to a package name. The array is examined when Perl does method resolution, which is covered in <a href="/5.39.2/perlobj">perlobj</a>.</p> <p>To load packages while adding them to <code>@ISA</code>, see the <a href="/5.39.2/parent">parent</a> pragma. The discouraged <a href="/5.39.2/base">base</a> pragma does this as well, but should not be used except when compatibility with the discouraged <a href="/5.39.2/fields">fields</a> pragma is required.</p> </dd> <dt id="$^M"><a class="permalink" href="#$%5EM">#</a><a id="M"></a>$^M </dt> <dd> <p>By default, running out of memory is an untrappable, fatal error. However, if suitably built, Perl can use the contents of <code>$^M</code> as an emergency memory pool after <code>die()</code>ing. Suppose that your Perl were compiled with <code>-DPERL_EMERGENCY_SBRK</code> and used Perl&#39;s malloc. Then</p> <pre><code>$^M = &#39;a&#39; x (1 &lt;&lt; 16);</code></pre> <p>would allocate a 64K buffer for use in an emergency. See the <a href="/5.39.2/INSTALL">INSTALL</a> file in the Perl distribution for information on how to add custom C compilation flags when compiling perl. To discourage casual use of this advanced feature, there is no <a href="/5.39.2/English">English</a> long name for this variable.</p> <p>This variable was added in Perl 5.004.</p> </dd> <dt id="${^MAX_NESTED_EVAL_BEGIN_BLOCKS}"><a class="permalink" href="#$%7B%5EMAX_NESTED_EVAL_BEGIN_BLOCKS%7D">#</a><a id="MAX_NESTED_EVAL_BEGIN_BLOCKS"></a>${^MAX_NESTED_EVAL_BEGIN_BLOCKS}</dt> <dd> <p>This variable determines the maximum number <code>eval EXPR</code>/<code>BEGIN</code> or <code>require</code>/<code>BEGIN</code> block nesting that is allowed. This means it also controls the maximum nesting of <code>use</code> statements as well.</p> <p>The default of 1000 should be sufficiently large for normal working purposes, and if you must raise it then you should be conservative with your choice or you may encounter segfaults from exhaustion of the C stack. It seems unlikely that real code has a use depth above 1000, but we have left this configurable just in case.</p> <p>When set to <code>0</code> then <code>BEGIN</code> blocks inside of <code>eval EXPR</code> or <code>require EXPR</code> are forbidden entirely and will trigger an exception which will terminate the compilation and in the case of <code>require</code> will throw an exception, or in the case of <code>eval</code> return the error in <code>$@</code> as usual.</p> <p>Consider the code</p> <pre><code class="plaintext">perl -le&#39;sub f { eval &quot;BEGIN { f() }&quot;; } f()&#39;</code></pre> <p>each invocation of <code>f()</code> will consume considerable C stack, and this variable is used to cause code like this to die instead of exhausting the C stack and triggering a segfault. Needless to say code like this is unusual, it is unlikely you will actually need to raise the setting. However it may be useful to set it to 0 for a limited time period to prevent BEGIN{} blocks from being executed during an <code>eval EXPR</code>.</p> <p>Note that setting this to 1 would NOT affect code like this:</p> <pre><code>BEGIN { $n += 1; BEGIN { $n += 2; BEGIN { $n += 4 } } }</code></pre> <p>The reason is that BEGIN blocks are executed immediately after they are completed, thus the innermost will execute before the ones which contain it have even finished compiling, and the depth will not go above 1. In fact the above code is equivalent to</p> <pre><code>BEGIN { $n+=4 } BEGIN { $n+=2 } BEGIN { $n+=1 }</code></pre> <p>which makes it obvious why a ${^MAX_EVAL_BEGIN_DEPTH} of 1 would not block this code.</p> <p>Only <code>BEGIN</code>&#39;s executed inside of an <code>eval</code> or <code>require</code> (possibly via <code>use</code>) are affected.</p> </dd> <dt id="$OSNAME"><a class="permalink" href="#$OSNAME">#</a><a id="OSNAME"></a>$OSNAME</dt> <dd> </dd> <dt id="$^O"><a class="permalink" href="#$%5EO">#</a><a id="O"></a>$^O </dt> <dd> <p>The name of the operating system under which this copy of Perl was built, as determined during the configuration process. For examples see <a href="/5.39.2/perlport#PLATFORMS">&quot;PLATFORMS&quot; in perlport</a>.</p> <p>The value is identical to <code>$Config{&#39;osname&#39;}</code>. See also <a href="/5.39.2/Config">Config</a> and the <b>-V</b> command-line switch documented in <a href="/5.39.2/perlrun#-V">perlrun</a>.</p> <p>In Windows platforms, <code>$^O</code> is not very helpful: since it is always <code>MSWin32</code>, it doesn&#39;t tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use <code>Win32::GetOSName()</code> or Win32::GetOSVersion() (see <a href="/5.39.2/Win32">Win32</a> and <a href="/5.39.2/perlport">perlport</a>) to distinguish between the variants.</p> <p>This variable was added in Perl 5.003.</p> </dd> <dt id="%SIG"><a class="permalink" href="#%25SIG">#</a><a id="SIG"></a>%SIG </dt> <dd> <p>The hash <code>%SIG</code> contains signal handlers for signals. For example:</p> <pre><code>sub handler { # 1st argument is signal name my($sig) = @_; print &quot;Caught a SIG$sig--shutting down\n&quot;; close(LOG); exit(0); } $SIG{&#39;INT&#39;} = \&amp;handler; $SIG{&#39;QUIT&#39;} = \&amp;handler; ... $SIG{&#39;INT&#39;} = &#39;DEFAULT&#39;; # restore default action $SIG{&#39;QUIT&#39;} = &#39;IGNORE&#39;; # ignore SIGQUIT</code></pre> <p>Using a value of <code>&#39;IGNORE&#39;</code> usually has the effect of ignoring the signal, except for the <code>CHLD</code> signal. See <a href="/5.39.2/perlipc">perlipc</a> for more about this special case. Using an empty string or <code>undef</code> as the value has the same effect as <code>&#39;DEFAULT&#39;</code>.</p> <p>Here are some other examples:</p> <pre><code>$SIG{&quot;PIPE&quot;} = &quot;Plumber&quot;; # assumes main::Plumber (not # recommended) $SIG{&quot;PIPE&quot;} = \&amp;Plumber; # just fine; assume current # Plumber $SIG{&quot;PIPE&quot;} = *Plumber; # somewhat esoteric $SIG{&quot;PIPE&quot;} = Plumber(); # oops, what did Plumber() # return??</code></pre> <p>Be sure not to use a bareword as the name of a signal handler, lest you inadvertently call it.</p> <p>Using a string that doesn&#39;t correspond to any existing function or a glob that doesn&#39;t contain a code slot is equivalent to <code>&#39;IGNORE&#39;</code>, but a warning is emitted when the handler is being called (the warning is not emitted for the internal hooks described below).</p> <p>If your system has the <code>sigaction()</code> function then signal handlers are installed using it. This means you get reliable signal handling.</p> <p>The default delivery policy of signals changed in Perl v5.8.0 from immediate (also known as &quot;unsafe&quot;) to deferred, also known as &quot;safe signals&quot;. See <a href="/5.39.2/perlipc">perlipc</a> for more information.</p> <p>Certain internal hooks can be also set using the <code>%SIG</code> hash. The routine indicated by <code>$SIG{__WARN__}</code> is called when a warning message is about to be printed. The warning message is passed as the first argument. The presence of a <code>__WARN__</code> hook causes the ordinary printing of warnings to <code>STDERR</code> to be suppressed. You can use this to save warnings in a variable, or turn warnings into fatal errors, like this:</p> <pre><code>local $SIG{__WARN__} = sub { die $_[0] }; eval $proggie;</code></pre> <p>As the <code>&#39;IGNORE&#39;</code> hook is not supported by <code>__WARN__</code>, its effect is the same as using <code>&#39;DEFAULT&#39;</code>. You can disable warnings using the empty subroutine:</p> <pre><code>local $SIG{__WARN__} = sub {};</code></pre> <p>The routine indicated by <code>$SIG{__DIE__}</code> is called when a fatal exception is about to be thrown. The error message is passed as the first argument. When a <code>__DIE__</code> hook routine returns, the exception processing continues as it would have in the absence of the hook, unless the hook routine itself exits via a <code>goto &amp;sub</code>, a loop exit, or a <code>die()</code>. The <code>__DIE__</code> handler is explicitly disabled during the call, so that you can die from a <code>__DIE__</code> handler. Similarly for <code>__WARN__</code>.</p> <p>The <code>$SIG{__DIE__}</code> hook is called even inside an <code>eval()</code>. It was never intended to happen this way, but an implementation glitch made this possible. This used to be deprecated, as it allowed strange action at a distance like rewriting a pending exception in <code>$@</code>. Plans to rectify this have been scrapped, as users found that rewriting a pending exception is actually a useful feature, and not a bug.</p> <p>The <code>$SIG{__DIE__}</code> doesn&#39;t support <code>&#39;IGNORE&#39;</code>; it has the same effect as <code>&#39;DEFAULT&#39;</code>.</p> <p><code>__DIE__</code>/<code>__WARN__</code> handlers are very special in one respect: they may be called to report (probable) errors found by the parser. In such a case the parser may be in inconsistent state, so any attempt to evaluate Perl code from such a handler will probably result in a segfault. This means that warnings or errors that result from parsing Perl should be used with extreme caution, like this:</p> <pre><code>require Carp if defined $^S; Carp::confess(&quot;Something wrong&quot;) if defined &amp;Carp::confess; die &quot;Something wrong, but could not load Carp to give &quot; . &quot;backtrace...\n\t&quot; . &quot;To see backtrace try starting Perl with -MCarp switch&quot;;</code></pre> <p>Here the first line will load <code>Carp</code> <i>unless</i> it is the parser who called the handler. The second line will print backtrace and die if <code>Carp</code> was available. The third line will be executed only if <code>Carp</code> was not available.</p> <p>Having to even think about the <code>$^S</code> variable in your exception handlers is simply wrong. <code>$SIG{__DIE__}</code> as currently implemented invites grievous and difficult to track down errors. Avoid it and use an <code>END{}</code> or CORE::GLOBAL::die override instead.</p> <p>See <a href="/5.39.2/perlfunc#die">&quot;die&quot; in perlfunc</a>, <a href="/5.39.2/perlfunc#warn">&quot;warn&quot; in perlfunc</a>, <a href="/5.39.2/perlfunc#eval">&quot;eval&quot; in perlfunc</a>, and <a href="/5.39.2/warnings">warnings</a> for additional information.</p> </dd> <dt id="%{^HOOK}"><a class="permalink" href="#%25%7B%5EHOOK%7D">#</a><a id="HOOK"></a>%{^HOOK} </dt> <dd> <p>This hash contains coderefs which are called when various perl keywords which are hard or impossible to wrap are called. The keys of this hash are named after the keyword that is being hooked, followed by two underbars and then a phase term; either &quot;before&quot; or &quot;after&quot;.</p> <p>Perl will throw an error if you attempt modify a key which is not documented to exist, or if you attempt to store anything other than a code reference or undef in the hash. If you wish to use an object to implement a hook you can use currying to embed the object into an anonymous code reference.</p> <p>Currently there is only one keyword which can be hooked, <code>require</code>, but it is expected that in future releases there will be additional keywords with hook support.</p> <dl> <dt id="require__before"><a class="permalink" href="#require__before">#</a>require__before</dt> <dd> <p>The routine indicated by <code>${^HOOK}{require__before}</code> is called by <code>require</code> <b>before</b> it checks <code>%INC</code>, looks up <code>@INC</code>, calls INC hooks, or compiles any code. It is called with a single argument, the filename for the item being required (package names are converted to paths). It may alter this filename to change what file is loaded. If the hook dies during execution then it will block the require from executing.</p> <p>In order to make it easy to perform an action with shared state both before and after the require keyword was executed the <code>require__before</code> hook may return a &quot;post-action&quot; coderef which will in turn be executed when the <code>require</code> completes. This coderef will be executed regardless as to whether the require completed succesfully or threw an exception. It will be called with the filename that was required. You can check %INC to determine if the require was successful. Any other return from the <code>require__before</code> hook will be silently ignored.</p> <p><code>require__before</code> hooks are called in FIFO order, and if the hook returns a code reference those code references will be called in FILO order. In other words if A requires B requires C, then <code>require__before</code> will be called first for A, then B and then C, and the post-action code reference will executed first for C, then B and then finally A.</p> <p>Well behaved code should ensure that when setting up a <code>require__before</code> hook that any prior installed hook will be called, and that their return value, if a code reference, will be called as well. See <a href="/5.39.2/perlfunc#require">&quot;require&quot; in perlfunc</a> for an example implementation.</p> </dd> <dt id="require__after"><a class="permalink" href="#require__after">#</a>require__after</dt> <dd> <p>The routine indicated by <code>${^HOOK}{require__after}</code> is called by <code>require</code> <b>after</b> the require completes. It is called with a single argument, the filename for the item being required (package names are converted to paths). It is executed when the <code>require</code> completes, either via exception or via completion of the require statement, and you can check <code>%INC</code> to determine if the require was successful.</p> <p>The <code>require__after</code> hook is called for each required file in FILO order. In other words if A requires B requires C, then <code>require__after</code> will be called first for C, then B and then A.</p> </dd> </dl> </dd> <dt id="$BASETIME"><a class="permalink" href="#$BASETIME">#</a><a id="BASETIME"></a>$BASETIME</dt> <dd> </dd> <dt id="$^T"><a class="permalink" href="#$%5ET">#</a><a id="T"></a>$^T </dt> <dd> <p>The time at which the program began running, in seconds since the epoch (beginning of 1970). The values returned by the <b>-M</b>, <b>-A</b>, and <b>-C</b> filetests are based on this value.</p> </dd> <dt id="$PERL_VERSION"><a class="permalink" href="#$PERL_VERSION">#</a><a id="PERL_VERSION"></a>$PERL_VERSION</dt> <dd> </dd> <dt id="$^V"><a class="permalink" href="#$%5EV">#</a><a id="V"></a>$^V </dt> <dd> <p>The revision, version, and subversion of the Perl interpreter, represented as a <a href="/5.39.2/version">version</a> object.</p> <p>This variable first appeared in perl v5.6.0; earlier versions of perl will see an undefined value. Before perl v5.10.0 <code>$^V</code> was represented as a v-string rather than a <a href="/5.39.2/version">version</a> object.</p> <p><code>$^V</code> can be used to determine whether the Perl interpreter executing a script is in the right range of versions. For example:</p> <pre><code class="plaintext">warn &quot;Hashes not randomized!\n&quot; if !$^V or $^V lt v5.8.1</code></pre> <p>While version objects overload stringification, to portably convert <code>$^V</code> into its string representation, use <code>sprintf()</code>&#39;s <code>&quot;%vd&quot;</code> conversion, which works for both v-strings or version objects:</p> <pre><code>printf &quot;version is v%vd\n&quot;, $^V; # Perl&#39;s version</code></pre> <p>See the documentation of <code>use VERSION</code> and <code>require VERSION</code> for a convenient way to fail if the running Perl interpreter is too old.</p> <p>See also <code><a href="#%24%5D">&quot;$]&quot;</a></code> for a decimal representation of the Perl version.</p> <p>The main advantage of <code>$^V</code> over <code>$]</code> is that, for Perl v5.10.0 or later, it overloads operators, allowing easy comparison against other version representations (e.g. decimal, literal v-string, &quot;v1.2.3&quot;, or objects). The disadvantage is that prior to v5.10.0, it was only a literal v-string, which can&#39;t be easily printed or compared, whereas the behavior of <code>$]</code> is unchanged on all versions of Perl.</p> <p>Mnemonic: use ^V for a version object.</p> </dd> <dt id="$EXECUTABLE_NAME"><a class="permalink" href="#$EXECUTABLE_NAME">#</a><a id="EXECUTABLE_NAME"></a>$EXECUTABLE_NAME</dt> <dd> </dd> <dt id="$^X"><a class="permalink" href="#$%5EX">#</a><a id="X"></a>$^X </dt> <dd> <p>The name used to execute the current copy of Perl, from C&#39;s <code>argv[0]</code> or (where supported) <i>/proc/self/exe</i>.</p> <p>Depending on the host operating system, the value of <code>$^X</code> may be a relative or absolute pathname of the perl program file, or may be the string used to invoke perl but not the pathname of the perl program file. Also, most operating systems permit invoking programs that are not in the PATH environment variable, so there is no guarantee that the value of <code>$^X</code> is in PATH. For VMS, the value may or may not include a version number.</p> <p>You usually can use the value of <code>$^X</code> to re-invoke an independent copy of the same perl that is currently running, e.g.,</p> <pre><code>@first_run = `$^X -le &quot;print int rand 100 for 1..100&quot;`;</code></pre> <p>But recall that not all operating systems support forking or capturing of the output of commands, so this complex statement may not be portable.</p> <p>It is not safe to use the value of <code>$^X</code> as a path name of a file, as some operating systems that have a mandatory suffix on executable files do not require use of the suffix when invoking a command. To convert the value of <code>$^X</code> to a path name, use the following statements:</p> <pre><code># Build up a set of file names (not command names). use Config; my $this_perl = $^X; if ($^O ne &#39;VMS&#39;) { $this_perl .= $Config{_exe} unless $this_perl =~ m/$Config{_exe}$/i; }</code></pre> <p>Because many operating systems permit anyone with read access to the Perl program file to make a copy of it, patch the copy, and then execute the copy, the security-conscious Perl programmer should take care to invoke the installed copy of perl, not the copy referenced by <code>$^X</code>. The following statements accomplish this goal, and produce a pathname that can be invoked as a command or referenced as a file.</p> <pre><code>use Config; my $secure_perl_path = $Config{perlpath}; if ($^O ne &#39;VMS&#39;) { $secure_perl_path .= $Config{_exe} unless $secure_perl_path =~ m/$Config{_exe}$/i; }</code></pre> </dd> </dl> <h2 id="Variables-related-to-regular-expressions"><a class="permalink" href="#Variables-related-to-regular-expressions">#</a><a id="Variables"></a>Variables related to regular expressions</h2> <p>Most of the special variables related to regular expressions are side effects. Perl sets these variables when it has completed a match successfully, so you should check the match result before using them. For instance:</p> <pre><code>if( /P(A)TT(ER)N/ ) { print &quot;I found $1 and $2\n&quot;; }</code></pre> <p>These variables are read-only and behave similarly to a dynamically scoped variable, with only a few exceptions which are explicitly documented as behaving otherwise. See the following section for more details.</p> <h3 id="Scoping-Rules-of-Regex-Variables"><a class="permalink" href="#Scoping-Rules-of-Regex-Variables">#</a><a id="Scoping"></a>Scoping Rules of Regex Variables</h3> <p>Regular expression variables allow the programmer to access the state of the most recent <i>successful</i> regex match in the current dynamic scope.</p> <p>The variables themselves are global and unscoped, but the data they access is scoped similarly to dynamically scoped variables, in that every successful match behaves as though it localizes a global state object to the current block or file scope. (See <a href="/5.39.2/perlsyn#Compound-Statements">&quot;Compound Statements&quot; in perlsyn</a> for more details on dynamic scoping and the <code>local</code> keyword.)</p> <p>A <i>successful match</i> includes any successful match performed by the search and replace operator <code>s///</code> as well as those performed by the <code>m//</code> operator.</p> <p>Consider the following code:</p> <pre><code>my @state; sub matchit { push @state, $1; # pushes &quot;baz&quot; my $str = shift; $str =~ /(zat)/; # matches &quot;zat&quot; push @state, $1; # pushes &quot;zat&quot; } { $str = &quot;foo bar baz blorp zat&quot;; $str =~ /(foo)/; # matches &quot;foo&quot; push @state, $1; # pushes &quot;foo&quot; { $str =~ /(pizza)/; # does NOT match push @state, $1; # pushes &quot;foo&quot; $str =~ /(bar)/; # matches &quot;bar&quot; push @state, $1; # pushes &quot;bar&quot; $str =~ /(baz)/; # matches &quot;baz&quot; matchit($str); # see above push @state, $1; # pushes &quot;baz&quot; } $str =~ s/noodles/rice/; # does NOT match push @state, $1; # pushes &quot;foo&quot; $str =~ s/(blorp)/zwoop/; # matches &quot;blorp&quot; push @state, $1; # pushes &quot;blorp&quot; } # the following prints &quot;foo, foo, bar, baz, zat, baz, foo, blorp&quot; print join &quot;,&quot;, @state;</code></pre> <p>Notice that each successful match in the exact same scope overrides the match context of the previous successful match, but that unsuccessful matches do not. Also note that in an inner nested scope the previous state from an outer dynamic scope persists until it has been overriden by another successful match, but that when the inner nested scope exits whatever match context was in effect before the inner successful match is restored when the scope concludes.</p> <p>It is a known issue that <code>goto LABEL</code> may interact poorly with the dynamically scoped match context. This may not be fixable, and is considered to be one of many good reasons to avoid <code>goto LABEL</code>.</p> <h3 id="Performance-issues"><a class="permalink" href="#Performance-issues">#</a><a id="Performance"></a>Performance issues</h3> <p>Traditionally in Perl, any use of any of the three variables <code>$`</code>, <code>$&amp;</code> or <code>$&#39;</code> (or their <code>use English</code> equivalents) anywhere in the code, caused all subsequent successful pattern matches to make a copy of the matched string, in case the code might subsequently access one of those variables. This imposed a considerable performance penalty across the whole program, so generally the use of these variables has been discouraged.</p> <p>In Perl 5.6.0 the <code>@-</code> and <code>@+</code> dynamic arrays were introduced that supply the indices of successful matches. So you could for example do this:</p> <pre><code>$str =~ /pattern/; print $`, $&amp;, $&#39;; # bad: performance hit print # good: no performance hit substr($str, 0, $-[0]), substr($str, $-[0], $+[0]-$-[0]), substr($str, $+[0]);</code></pre> <p>In Perl 5.10.0 the <code>/p</code> match operator flag and the <code>${^PREMATCH}</code>, <code>${^MATCH}</code>, and <code>${^POSTMATCH}</code> variables were introduced, that allowed you to suffer the penalties only on patterns marked with <code>/p</code>.</p> <p>In Perl 5.18.0 onwards, perl started noting the presence of each of the three variables separately, and only copied that part of the string required; so in</p> <pre><code class="plaintext">$`; $&amp;; &quot;abcdefgh&quot; =~ /d/</code></pre> <p>perl would only copy the &quot;abcd&quot; part of the string. That could make a big difference in something like</p> <pre><code>$str = &#39;x&#39; x 1_000_000; $&amp;; # whoops $str =~ /x/g # one char copied a million times, not a million chars</code></pre> <p>In Perl 5.20.0 a new copy-on-write system was enabled by default, which finally fixes most of the performance issues with these three variables, and makes them safe to use anywhere.</p> <p>The <code>Devel::NYTProf</code> and <code>Devel::FindAmpersand</code> modules can help you find uses of these problematic match variables in your code.</p> <dl> <dt id="$&lt;digits&gt;-($1,-$2,-...)"><a class="permalink" href="#$%3Cdigits%3E-($1,-$2,-...)">#</a><a id="digits-1-2"></a>$&lt;<i>digits</i>&gt; ($1, $2, ...) </dt> <dd> <p>Contains the subpattern from the corresponding set of capturing parentheses from the last successful pattern match in the current dynamic scope. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>.)</p> <p>Note there is a distinction between a capture buffer which matches the empty string a capture buffer which is optional. Eg, <code>(x?)</code> and <code>(x)?</code> The latter may be undef, the former not.</p> <p>These variables are read-only.</p> <p>Mnemonic: like \digits.</p> </dd> <dt id="@{^CAPTURE}"><a class="permalink" href="#@%7B%5ECAPTURE%7D">#</a><a id="CAPTURE"></a>@{^CAPTURE} </dt> <dd> <p>An array which exposes the contents of the capture buffers, if any, of the last successful pattern match, not counting patterns matched in nested blocks that have been exited already.</p> <p>Note that the 0 index of @{^CAPTURE} is equivalent to $1, the 1 index is equivalent to $2, etc.</p> <pre><code>if (&quot;foal&quot;=~/(.)(.)(.)(.)/) { print join &quot;-&quot;, @{^CAPTURE}; }</code></pre> <p>should output &quot;f-o-a-l&quot;.</p> <p>See also <a href="#%24%3Cdigits%3E-(%241%2C-%242%2C-...)">&quot;$&lt;<i>digits</i>&gt; ($1, $2, ...)&quot;</a>, <a href="#%25%7B%5ECAPTURE%7D">&quot;%{^CAPTURE}&quot;</a> and <a href="#%25%7B%5ECAPTURE_ALL%7D">&quot;%{^CAPTURE_ALL}&quot;</a>.</p> <p>Note that unlike most other regex magic variables there is no single letter equivalent to <code>@{^CAPTURE}</code>. Also be aware that when interpolating subscripts of this array you <b>must</b> use the demarcated variable form, for instance</p> <pre><code class="plaintext">print &quot;${^CAPTURE[0]}&quot;</code></pre> <p>see <a href="/5.39.2/perldata#Demarcated-variable-names-using-braces">&quot;Demarcated variable names using braces&quot; in perldata</a> for more information on this form and its uses.</p> <p>This variable was added in 5.25.7</p> </dd> <dt id="$MATCH"><a class="permalink" href="#$MATCH">#</a><a id="MATCH"></a>$MATCH</dt> <dd> </dd> <dt id="$&amp;"><a class="permalink" href="#$&amp;">#</a><a id="pod8"></a>$&amp; </dt> <dd> <p>The string matched by the last successful pattern match. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>.)</p> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above for the serious performance implications of using this variable (even once) in your code.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>Mnemonic: like <code>&amp;</code> in some editors.</p> </dd> <dt id="${^MATCH}"><a class="permalink" href="#$%7B%5EMATCH%7D">#</a><a id="MATCH1"></a>${^MATCH} </dt> <dd> <p>It is only guaranteed to return a defined value when the pattern was compiled or executed with the <code>/p</code> modifier.</p> <p>This is similar to <code>$&amp;</code> (<code>$MATCH</code>) except that to use it you must use the <code>/p</code> modifier when executing the pattern, and it does not incur and performance penalty associated with that variable.</p> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above.</p> <p>This variable was added in Perl v5.10.0.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> </dd> <dt id="$PREMATCH"><a class="permalink" href="#$PREMATCH">#</a><a id="PREMATCH"></a>$PREMATCH</dt> <dd> </dd> <dt id="$`"><a class="permalink" href="#$%60">#</a><a id="pod9"></a>$` </dt> <dd> <p>The string preceding whatever was matched by the last successful pattern match. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>).</p> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above for the serious performance implications of using this variable (even once) in your code.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>Mnemonic: <code>`</code> often precedes a quoted string.</p> </dd> <dt id="${^PREMATCH}"><a class="permalink" href="#$%7B%5EPREMATCH%7D">#</a><a id="PREMATCH1"></a>${^PREMATCH} </dt> <dd> <p>It is only guaranteed to return a defined value when the pattern was executed with the <code>/p</code> modifier.</p> <p>This is similar to <code>$`</code> ($PREMATCH) except that to use it you must use the <code>/p</code> modifier when executing the pattern, and it does not incur and performance penalty associated with that variable.</p> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above.</p> <p>This variable was added in Perl v5.10.0.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> </dd> <dt id="$POSTMATCH"><a class="permalink" href="#$POSTMATCH">#</a><a id="POSTMATCH"></a>$POSTMATCH</dt> <dd> </dd> <dt id="$&#39;"><a class="permalink" href="#$&#39;">#</a><a id="pod10"></a>$&#39; </dt> <dd> <p>The string following whatever was matched by the last successful pattern match. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>). Example:</p> <pre><code>local $_ = &#39;abcdefghi&#39;; /def/; print &quot;$`:$&amp;:$&#39;\n&quot;; # prints abc:def:ghi</code></pre> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above for the serious performance implications of using this variable (even once) in your code.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>Mnemonic: <code>&#39;</code> often follows a quoted string.</p> </dd> <dt id="${^POSTMATCH}"><a class="permalink" href="#$%7B%5EPOSTMATCH%7D">#</a><a id="POSTMATCH1"></a>${^POSTMATCH} </dt> <dd> <p>It is only guaranteed to return a defined value when the pattern was compiled or executed with the <code>/p</code> modifier.</p> <p>This is similar to <code>$&#39;</code> (<code>$POSTMATCH</code>) except that to use it you must use the <code>/p</code> modifier when executing the pattern, and it does not incur and performance penalty associated with that variable.</p> <p>See <a href="#Performance-issues">&quot;Performance issues&quot;</a> above.</p> <p>This variable was added in Perl v5.10.0.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> </dd> <dt id="$LAST_PAREN_MATCH"><a class="permalink" href="#$LAST_PAREN_MATCH">#</a><a id="LAST_PAREN_MATCH"></a>$LAST_PAREN_MATCH</dt> <dd> </dd> <dt id="$+"><a class="permalink" href="#$+">#</a><a id="pod11"></a>$+ </dt> <dd> <p>The text matched by the highest used capture group of the last successful search pattern. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>). It is logically equivalent to the highest numbered capture variable (<code>$1</code>, <code>$2</code>, ...) which has a defined value.</p> <p>This is useful if you don&#39;t know which one of a set of alternative patterns matched. For example:</p> <pre><code>/Version: (.*)|Revision: (.*)/ &amp;&amp; ($rev = $+);</code></pre> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>Mnemonic: be positive and forward looking.</p> </dd> <dt id="$LAST_SUBMATCH_RESULT"><a class="permalink" href="#$LAST_SUBMATCH_RESULT">#</a><a id="LAST_SUBMATCH_RESULT"></a>$LAST_SUBMATCH_RESULT</dt> <dd> </dd> <dt id="$^N"><a class="permalink" href="#$%5EN">#</a><a id="N"></a>$^N </dt> <dd> <p>The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful match. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>).</p> <p>This is subtly different from <code>$+</code>. For example in</p> <pre><code class="plaintext">&quot;ab&quot; =~ /^((.)(.))$/</code></pre> <p>we have</p> <pre><code>$1,$^N have the value &quot;ab&quot; $2 has the value &quot;a&quot; $3,$+ have the value &quot;b&quot;</code></pre> <p>This is primarily used inside <code>(?{...})</code> blocks for examining text recently matched. For example, to effectively capture text to a variable (in addition to <code>$1</code>, <code>$2</code>, etc.), replace <code>(...)</code> with</p> <pre><code>(?:(...)(?{ $var = $^N }))</code></pre> <p>By setting and then using <code>$var</code> in this way relieves you from having to worry about exactly which numbered set of parentheses they are.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>This variable was added in Perl v5.8.0.</p> <p>Mnemonic: the (possibly) Nested parenthesis that most recently closed.</p> </dd> <dt id="@LAST_MATCH_END"><a class="permalink" href="#@LAST_MATCH_END">#</a><a id="LAST_MATCH_END"></a>@LAST_MATCH_END</dt> <dd> </dd> <dt id="@+"><a class="permalink" href="#@+">#</a><a id="pod12"></a>@+ </dt> <dd> <p>This array holds the offsets of the ends of the last successful match and any matching capture buffers that the pattern contains. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>)</p> <p>The number of elements it contains will be one more than the number of capture buffers in the pattern, regardless of which capture buffers actually matched. You can use this to determine how many capture buffers there are in the pattern. (As opposed to <code>@-</code> which may have fewer elements.)</p> <p><code>$+[0]</code> is the offset into the string of the end of the entire match. This is the same value as what the <code>pos</code> function returns when called on the variable that was matched against. The <i>n</i>th element of this array holds the offset of the <i>n</i>th submatch, so <code>$+[1]</code> is the offset past where <code>$1</code> ends, <code>$+[2]</code> the offset past where <code>$2</code> ends, and so on. You can use <code>$#+</code> to determine how many subgroups were in the last successful match. See the examples given for the <code>@-</code> variable.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>This variable was added in Perl v5.6.0.</p> </dd> <dt id="%{^CAPTURE}"><a class="permalink" href="#%25%7B%5ECAPTURE%7D">#</a><a id="CAPTURE1"></a>%{^CAPTURE}</dt> <dd> </dd> <dt id="%LAST_PAREN_MATCH"><a class="permalink" href="#%25LAST_PAREN_MATCH">#</a><a id="LAST_PAREN_MATCH1"></a>%LAST_PAREN_MATCH</dt> <dd> </dd> <dt id="%+"><a class="permalink" href="#%25+">#</a><a id="pod13"></a>%+ </dt> <dd> <p>Similar to <code>@+</code>, the <code>%+</code> hash allows access to the named capture buffers, should they exist, in the last successful match in the currently active dynamic scope. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>).</p> <p>For example, <code>$+{foo}</code> is equivalent to <code>$1</code> after the following match:</p> <pre><code>&#39;foo&#39; =~ /(?&lt;foo&gt;foo)/;</code></pre> <p>The keys of the <code>%+</code> hash list only the names of buffers that have captured (and that are thus associated to defined values).</p> <p>If multiple distinct capture groups have the same name, then <code>$+{NAME}</code> will refer to the leftmost defined group in the match.</p> <p>The underlying behaviour of <code>%+</code> is provided by the <a href="/5.39.2/Tie::Hash::NamedCapture">Tie::Hash::NamedCapture</a> module.</p> <p><b>Note:</b> <code>%-</code> and <code>%+</code> are tied views into a common internal hash associated with the last successful regular expression. Therefore mixing iterative access to them via <code>each</code> may have unpredictable results. Likewise, if the last successful match changes, then the results may be surprising.</p> <p>This variable was added in Perl v5.10.0. The <code>%{^CAPTURE}</code> alias was added in 5.25.7.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> </dd> <dt id="@LAST_MATCH_START"><a class="permalink" href="#@LAST_MATCH_START">#</a><a id="LAST_MATCH_START"></a>@LAST_MATCH_START</dt> <dd> </dd> <dt id="@-"><a class="permalink" href="#@-">#</a><a id="pod14"></a>@- </dt> <dd> <p>This array holds the offsets of the beginnings of the last successful match and any capture buffers it contains. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>).</p> <p>The number of elements it contains will be one more than the number of the highest capture buffers (also called a subgroup) that actually matched something. (As opposed to <code>@+</code> which may have fewer elements.)</p> <p><code>$-[0]</code> is the offset of the start of the last successful match. <code>$-[<i>n</i>]</code> is the offset of the start of the substring matched by <i>n</i>-th subpattern, or undef if the subpattern did not match.</p> <p>Thus, after a match against <code>$_</code>, <code>$&amp;</code> coincides with <code>substr $_, $-[0], $+[0] - $-[0]</code>. Similarly, <code>$<i>n</i></code> coincides with <code>substr $_, $-[n], $+[n] - $-[n]</code> if <code>$-[n]</code> is defined, and <code>$+</code> coincides with <code>substr $_, $-[$#-], $+[$#-] - $-[$#-]</code>. One can use <code>$#-</code> to find the last matched subgroup in the last successful match. Contrast with <code>$#+</code>, the number of subgroups in the regular expression.</p> <p><code>$-[0]</code> is the offset into the string of the beginning of the entire match. The <i>n</i>th element of this array holds the offset of the <i>n</i>th submatch, so <code>$-[1]</code> is the offset where <code>$1</code> begins, <code>$-[2]</code> the offset where <code>$2</code> begins, and so on.</p> <p>After a match against some variable <code>$var</code>:</p> <dl> <dt id="$`-is-the-same-as-substr($var,-0,-$-[0])"><a class="permalink" href="#$%60-is-the-same-as-substr($var,-0,-$-%5B0%5D)">#</a><a id="is-the-same-as-substr-var-0---0"></a><code>$`</code> is the same as <code>substr($var, 0, $-[0])</code></dt> <dd> </dd> <dt id="$&amp;-is-the-same-as-substr($var,-$-[0],-$+[0]-$-[0])"><a class="permalink" href="#$&amp;-is-the-same-as-substr($var,-$-%5B0%5D,-$+%5B0%5D-$-%5B0%5D)">#</a><a id="is-the-same-as-substr-var---0-0-----0"></a><code>$&amp;</code> is the same as <code>substr($var, $-[0], $+[0] - $-[0])</code></dt> <dd> </dd> <dt id="$&#39;-is-the-same-as-substr($var,-$+[0])"><a class="permalink" href="#$&#39;-is-the-same-as-substr($var,-$+%5B0%5D)">#</a><a id="is-the-same-as-substr-var-0"></a><code>$&#39;</code> is the same as <code>substr($var, $+[0])</code></dt> <dd> </dd> <dt id="$1-is-the-same-as-substr($var,-$-[1],-$+[1]-$-[1])"><a class="permalink" href="#$1-is-the-same-as-substr($var,-$-%5B1%5D,-$+%5B1%5D-$-%5B1%5D)">#</a><a id="is-the-same-as-substr-var---1-1-----1"></a><code>$1</code> is the same as <code>substr($var, $-[1], $+[1] - $-[1])</code></dt> <dd> </dd> <dt id="$2-is-the-same-as-substr($var,-$-[2],-$+[2]-$-[2])"><a class="permalink" href="#$2-is-the-same-as-substr($var,-$-%5B2%5D,-$+%5B2%5D-$-%5B2%5D)">#</a><a id="is-the-same-as-substr-var---2-2-----2"></a><code>$2</code> is the same as <code>substr($var, $-[2], $+[2] - $-[2])</code></dt> <dd> </dd> <dt id="$3-is-the-same-as-substr($var,-$-[3],-$+[3]-$-[3])"><a class="permalink" href="#$3-is-the-same-as-substr($var,-$-%5B3%5D,-$+%5B3%5D-$-%5B3%5D)">#</a><a id="is-the-same-as-substr-var---3-3-----3"></a><code>$3</code> is the same as <code>substr($var, $-[3], $+[3] - $-[3])</code></dt> <dd> </dd> </dl> <p>This variable is read-only, and its value is dynamically scoped.</p> <p>This variable was added in Perl v5.6.0.</p> </dd> <dt id="%{^CAPTURE_ALL}"><a class="permalink" href="#%25%7B%5ECAPTURE_ALL%7D">#</a><a id="CAPTURE_ALL"></a>%{^CAPTURE_ALL} </dt> <dd> </dd> <dt id="%-"><a class="permalink" href="#%25-">#</a><a id="pod15"></a>%- </dt> <dd> <p>Similar to <code>%+</code>, this variable allows access to the named capture groups in the last successful match in the currently active dynamic scope. (See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>). To each capture group name found in the regular expression, it associates a reference to an array containing the list of values captured by all buffers with that name (should there be several of them), in the order where they appear.</p> <p>Here&#39;s an example:</p> <pre><code>if (&#39;1234&#39; =~ /(?&lt;A&gt;1)(?&lt;B&gt;2)(?&lt;A&gt;3)(?&lt;B&gt;4)/) { foreach my $bufname (sort keys %-) { my $ary = $-{$bufname}; foreach my $idx (0..$#$ary) { print &quot;\$-{$bufname}[$idx] : &quot;, (defined($ary-&gt;[$idx]) ? &quot;&#39;$ary-&gt;[$idx]&#39;&quot; : &quot;undef&quot;), &quot;\n&quot;; } } }</code></pre> <p>would print out:</p> <pre><code class="plaintext">$-{A}[0] : &#39;1&#39; $-{A}[1] : &#39;3&#39; $-{B}[0] : &#39;2&#39; $-{B}[1] : &#39;4&#39;</code></pre> <p>The keys of the <code>%-</code> hash correspond to all buffer names found in the regular expression.</p> <p>The behaviour of <code>%-</code> is implemented via the <a href="/5.39.2/Tie::Hash::NamedCapture">Tie::Hash::NamedCapture</a> module.</p> <p><b>Note:</b> <code>%-</code> and <code>%+</code> are tied views into a common internal hash associated with the last successful regular expression. Therefore mixing iterative access to them via <code>each</code> may have unpredictable results. Likewise, if the last successful match changes, then the results may be surprising. See <a href="#Scoping-Rules-of-Regex-Variables">&quot;Scoping Rules of Regex Variables&quot;</a>.</p> <p>This variable was added in Perl v5.10.0. The <code>%{^CAPTURE_ALL}</code> alias was added in 5.25.7.</p> <p>This variable is read-only, and its value is dynamically scoped.</p> </dd> <dt id="${^LAST_SUCCESSFUL_PATTERN}"><a class="permalink" href="#$%7B%5ELAST_SUCCESSFUL_PATTERN%7D">#</a><a id="LAST_SUCCESSFUL_PATTERN"></a>${^LAST_SUCCESSFUL_PATTERN}</dt> <dd> <p>The last successful pattern that matched in the current scope. The empty pattern defaults to matching to this. For instance:</p> <pre><code>if (m/foo/ || m/bar/) { s//BLAH/; }</code></pre> <p>and</p> <pre><code>if (m/foo/ || m/bar/) { s/${^LAST_SUCCESSFUL_PATTERN}/BLAH/; }</code></pre> <p>are equivalent.</p> <p>You can use this to debug which pattern matched last, or to match with it again.</p> <p>Added in Perl 5.37.10.</p> </dd> <dt id="$LAST_REGEXP_CODE_RESULT"><a class="permalink" href="#$LAST_REGEXP_CODE_RESULT">#</a><a id="LAST_REGEXP_CODE_RESULT"></a>$LAST_REGEXP_CODE_RESULT</dt> <dd> </dd> <dt id="$^R"><a class="permalink" href="#$%5ER">#</a><a id="R"></a>$^R </dt> <dd> <p>The result of evaluation of the last successful <code>(?{ code })</code> regular expression assertion (see <a href="/5.39.2/perlre">perlre</a>).</p> <p>This variable may be written to, and its value is scoped normally, unlike most other regex variables.</p> <p>This variable was added in Perl 5.005.</p> </dd> <dt id="${^RE_COMPILE_RECURSION_LIMIT}"><a class="permalink" href="#$%7B%5ERE_COMPILE_RECURSION_LIMIT%7D">#</a><a id="RE_COMPILE_RECURSION_LIMIT"></a>${^RE_COMPILE_RECURSION_LIMIT} </dt> <dd> <p>The current value giving the maximum number of open but unclosed parenthetical groups there may be at any point during a regular expression compilation. The default is currently 1000 nested groups. You may adjust it depending on your needs and the amount of memory available.</p> <p>This variable was added in Perl v5.30.0.</p> </dd> <dt id="${^RE_DEBUG_FLAGS}"><a class="permalink" href="#$%7B%5ERE_DEBUG_FLAGS%7D">#</a><a id="RE_DEBUG_FLAGS"></a>${^RE_DEBUG_FLAGS} </dt> <dd> <p>The current value of the regex debugging flags. Set to 0 for no debug output even when the <code>re &#39;debug&#39;</code> module is loaded. See <a href="/5.39.2/re">re</a> for details.</p> <p>This variable was added in Perl v5.10.0.</p> </dd> <dt id="${^RE_TRIE_MAXBUF}"><a class="permalink" href="#$%7B%5ERE_TRIE_MAXBUF%7D">#</a><a id="RE_TRIE_MAXBUF"></a>${^RE_TRIE_MAXBUF} </dt> <dd> <p>Controls how certain regex optimisations are applied and how much memory they utilize. This value by default is 65536 which corresponds to a 512kB temporary cache. Set this to a higher value to trade memory for speed when matching large alternations. Set it to a lower value if you want the optimisations to be as conservative of memory as possible but still occur, and set it to a negative value to prevent the optimisation and conserve the most memory. Under normal situations this variable should be of no interest to you.</p> <p>This variable was added in Perl v5.10.0.</p> </dd> </dl> <h2 id="Variables-related-to-filehandles"><a class="permalink" href="#Variables-related-to-filehandles">#</a><a id="Variables1"></a>Variables related to filehandles</h2> <p>Variables that depend on the currently selected filehandle may be set by calling an appropriate object method on the <code>IO::Handle</code> object, although this is less efficient than using the regular built-in variables. (Summary lines below for this contain the word HANDLE.) First you must say</p> <pre><code>use IO::Handle;</code></pre> <p>after which you may use either</p> <pre><code class="plaintext">method HANDLE EXPR</code></pre> <p>or more safely,</p> <pre><code>HANDLE-&gt;method(EXPR)</code></pre> <p>Each method returns the old value of the <code>IO::Handle</code> attribute. The methods each take an optional EXPR, which, if supplied, specifies the new value for the <code>IO::Handle</code> attribute in question. If not supplied, most methods do nothing to the current value--except for <code>autoflush()</code>, which will assume a 1 for you, just to be different.</p> <p>Because loading in the <code>IO::Handle</code> class is an expensive operation, you should learn how to use the regular built-in variables.</p> <p>A few of these variables are considered &quot;read-only&quot;. This means that if you try to assign to this variable, either directly or indirectly through a reference, you&#39;ll raise a run-time exception.</p> <p>You should be very careful when modifying the default values of most special variables described in this document. In most cases you want to localize these variables before changing them, since if you don&#39;t, the change may affect other modules which rely on the default values of the special variables that you have changed. This is one of the correct ways to read the whole file at once:</p> <pre><code>open my $fh, &quot;&lt;&quot;, &quot;foo&quot; or die $!; local $/; # enable localized slurp mode my $content = &lt;$fh&gt;; close $fh;</code></pre> <p>But the following code is quite bad:</p> <pre><code>open my $fh, &quot;&lt;&quot;, &quot;foo&quot; or die $!; undef $/; # enable slurp mode my $content = &lt;$fh&gt;; close $fh;</code></pre> <p>since some other module, may want to read data from some file in the default &quot;line mode&quot;, so if the code we have just presented has been executed, the global value of <code>$/</code> is now changed for any other code running inside the same Perl interpreter.</p> <p>Usually when a variable is localized you want to make sure that this change affects the shortest scope possible. So unless you are already inside some short <code>{}</code> block, you should create one yourself. For example:</p> <pre><code>my $content = &#39;&#39;; open my $fh, &quot;&lt;&quot;, &quot;foo&quot; or die $!; { local $/; $content = &lt;$fh&gt;; } close $fh;</code></pre> <p>Here is an example of how your own code can go broken:</p> <pre><code>for ( 1..3 ){ $\ = &quot;\r\n&quot;; nasty_break(); print &quot;$_&quot;; } sub nasty_break { $\ = &quot;\f&quot;; # do something with $_ }</code></pre> <p>You probably expect this code to print the equivalent of</p> <pre><code class="plaintext">&quot;1\r\n2\r\n3\r\n&quot;</code></pre> <p>but instead you get:</p> <pre><code class="plaintext">&quot;1\f2\f3\f&quot;</code></pre> <p>Why? Because <code>nasty_break()</code> modifies <code>$\</code> without localizing it first. The value you set in <code>nasty_break()</code> is still there when you return. The fix is to add <code>local()</code> so the value doesn&#39;t leak out of <code>nasty_break()</code>:</p> <pre><code>local $\ = &quot;\f&quot;;</code></pre> <p>It&#39;s easy to notice the problem in such a short example, but in more complicated code you are looking for trouble if you don&#39;t localize changes to the special variables.</p> <dl> <dt id="$ARGV"><a class="permalink" href="#$ARGV">#</a><a id="ARGV1"></a>$ARGV </dt> <dd> <p>Contains the name of the current file when reading from <code>&lt;&gt;</code>.</p> </dd> <dt id="@ARGV"><a class="permalink" href="#@ARGV">#</a><a id="ARGV2"></a>@ARGV </dt> <dd> <p>The array <code>@ARGV</code> contains the command-line arguments intended for the script. <code>$#ARGV</code> is generally the number of arguments minus one, because <code>$ARGV[0]</code> is the first argument, <i>not</i> the program&#39;s command name itself. See <a href="#%240">&quot;$0&quot;</a> for the command name.</p> </dd> <dt id="ARGV"><a class="permalink" href="#ARGV">#</a>ARGV </dt> <dd> <p>The special filehandle that iterates over command-line filenames in <code>@ARGV</code>. Usually written as the null filehandle in the angle operator <code>&lt;&gt;</code>. Note that currently <code>ARGV</code> only has its magical effect within the <code>&lt;&gt;</code> operator; elsewhere it is just a plain filehandle corresponding to the last file opened by <code>&lt;&gt;</code>. In particular, passing <code>\*ARGV</code> as a parameter to a function that expects a filehandle may not cause your function to automatically read the contents of all the files in <code>@ARGV</code>.</p> </dd> <dt id="ARGVOUT"><a class="permalink" href="#ARGVOUT">#</a>ARGVOUT </dt> <dd> <p>The special filehandle that points to the currently open output file when doing edit-in-place processing with <b>-i</b>. Useful when you have to do a lot of inserting and don&#39;t want to keep modifying <code>$_</code>. See <a href="/5.39.2/perlrun#-i%5Bextension%5D">perlrun</a> for the <b>-i</b> switch.</p> </dd> <dt id="IO::Handle-&gt;output_field_separator(-EXPR-)"><a class="permalink" href="#IO::Handle-%3Eoutput_field_separator(-EXPR-)">#</a><a id="IO"></a><a id="IO::Handle-output_field_separator-EXPR"></a>IO::Handle-&gt;output_field_separator( EXPR )</dt> <dd> </dd> <dt id="$OUTPUT_FIELD_SEPARATOR"><a class="permalink" href="#$OUTPUT_FIELD_SEPARATOR">#</a><a id="OUTPUT_FIELD_SEPARATOR"></a>$OUTPUT_FIELD_SEPARATOR</dt> <dd> </dd> <dt id="$OFS"><a class="permalink" href="#$OFS">#</a><a id="OFS"></a>$OFS</dt> <dd> </dd> <dt id="$,"><a class="permalink" href="#$,">#</a><a id="pod16"></a>$, </dt> <dd> <p>The output field separator for the print operator. If defined, this value is printed between each of print&#39;s arguments. Default is <code>undef</code>.</p> <p>You cannot call <code>output_field_separator()</code> on a handle, only as a static method. See <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> <p>Mnemonic: what is printed when there is a &quot;,&quot; in your print statement.</p> </dd> <dt id="HANDLE-&gt;input_line_number(-EXPR-)"><a class="permalink" href="#HANDLE-%3Einput_line_number(-EXPR-)">#</a><a id="HANDLE"></a><a id="HANDLE-input_line_number-EXPR"></a>HANDLE-&gt;input_line_number( EXPR )</dt> <dd> </dd> <dt id="$INPUT_LINE_NUMBER"><a class="permalink" href="#$INPUT_LINE_NUMBER">#</a><a id="INPUT_LINE_NUMBER"></a>$INPUT_LINE_NUMBER</dt> <dd> </dd> <dt id="$NR"><a class="permalink" href="#$NR">#</a><a id="NR"></a>$NR</dt> <dd> </dd> <dt id="$."><a class="permalink" href="#$.">#</a><a id="pod17"></a>$. </dt> <dd> <p>Current line number for the last filehandle accessed.</p> <p>Each filehandle in Perl counts the number of lines that have been read from it. (Depending on the value of <code>$/</code>, Perl&#39;s idea of what constitutes a line may not match yours.) When a line is read from a filehandle (via <code>readline()</code> or <code>&lt;&gt;</code>), or when <code>tell()</code> or <code>seek()</code> is called on it, <code>$.</code> becomes an alias to the line counter for that filehandle.</p> <p>You can adjust the counter by assigning to <code>$.</code>, but this will not actually move the seek pointer. <i>Localizing <code>$.</code> will not localize the filehandle&#39;s line count</i>. Instead, it will localize perl&#39;s notion of which filehandle <code>$.</code> is currently aliased to.</p> <p><code>$.</code> is reset when the filehandle is closed, but <b>not</b> when an open filehandle is reopened without an intervening <code>close()</code>. For more details, see <a href="/5.39.2/perlop#I%2FO-Operators">&quot;I/O Operators&quot; in perlop</a>. Because <code>&lt;&gt;</code> never does an explicit close, line numbers increase across <code>ARGV</code> files (but see examples in <a href="/5.39.2/perlfunc#eof">&quot;eof&quot; in perlfunc</a>).</p> <p>You can also use <code>HANDLE-&gt;input_line_number(EXPR)</code> to access the line counter for a given filehandle without having to worry about which handle you last accessed.</p> <p>Mnemonic: many programs use &quot;.&quot; to mean the current line number.</p> </dd> <dt id="IO::Handle-&gt;input_record_separator(-EXPR-)"><a class="permalink" href="#IO::Handle-%3Einput_record_separator(-EXPR-)">#</a><a id="IO1"></a><a id="IO::Handle-input_record_separator-EXPR"></a>IO::Handle-&gt;input_record_separator( EXPR )</dt> <dd> </dd> <dt id="$INPUT_RECORD_SEPARATOR"><a class="permalink" href="#$INPUT_RECORD_SEPARATOR">#</a><a id="INPUT_RECORD_SEPARATOR"></a>$INPUT_RECORD_SEPARATOR</dt> <dd> </dd> <dt id="$RS"><a class="permalink" href="#$RS">#</a><a id="RS"></a>$RS</dt> <dd> </dd> <dt id="$/"><a class="permalink" href="#$/">#</a><a id="pod18"></a>$/ </dt> <dd> <p>The input record separator, newline by default. This influences Perl&#39;s idea of what a &quot;line&quot; is. Works like <b>awk</b>&#39;s RS variable, including treating empty lines as a terminator if set to the null string (an empty line cannot contain any spaces or tabs). You may set it to a multi-character string to match a multi-character terminator, or to <code>undef</code> to read through the end of file. Setting it to <code>&quot;\n\n&quot;</code> means something slightly different than setting to <code>&quot;&quot;</code>, if the file contains consecutive empty lines. Setting to <code>&quot;&quot;</code> will treat two or more consecutive empty lines as a single empty line. Setting to <code>&quot;\n\n&quot;</code> will blindly assume that the next input character belongs to the next paragraph, even if it&#39;s a newline.</p> <pre><code>local $/; # enable &quot;slurp&quot; mode local $_ = &lt;FH&gt;; # whole file now here s/\n[ \t]+/ /g;</code></pre> <p>Remember: the value of <code>$/</code> is a string, not a regex. <b>awk</b> has to be better for something. :-)</p> <p>Setting <code>$/</code> to an empty string -- the so-called <i>paragraph mode</i> -- merits special attention. When <code>$/</code> is set to <code>&quot;&quot;</code> and the entire file is read in with that setting, any sequence of one or more consecutive newlines at the beginning of the file is discarded. With the exception of the final record in the file, each sequence of characters ending in two or more newlines is treated as one record and is read in to end in exactly two newlines. If the last record in the file ends in zero or one consecutive newlines, that record is read in with that number of newlines. If the last record ends in two or more consecutive newlines, it is read in with two newlines like all preceding records.</p> <p>Suppose we wrote the following string to a file:</p> <pre><code>my $string = &quot;\n\n\n&quot;; $string .= &quot;alpha beta\ngamma delta\n\n\n&quot;; $string .= &quot;epsilon zeta eta\n\n&quot;; $string .= &quot;theta\n&quot;; my $file = &#39;simple_file.txt&#39;; open my $OUT, &#39;&gt;&#39;, $file or die; print $OUT $string; close $OUT or die;</code></pre> <p>Now we read that file in paragraph mode:</p> <pre><code>local $/ = &quot;&quot;; # paragraph mode open my $IN, &#39;&lt;&#39;, $file or die; my @records = &lt;$IN&gt;; close $IN or die;</code></pre> <p><code>@records</code> will consist of these 3 strings:</p> <pre><code class="plaintext">( &quot;alpha beta\ngamma delta\n\n&quot;, &quot;epsilon zeta eta\n\n&quot;, &quot;theta\n&quot;, )</code></pre> <p>Setting <code>$/</code> to a reference to an integer, scalar containing an integer, or scalar that&#39;s convertible to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer number of characters. So this:</p> <pre><code>local $/ = \32768; # or \&quot;32768&quot;, or \$var_containing_32768 open my $fh, &quot;&lt;&quot;, $myfile or die $!; local $_ = &lt;$fh&gt;;</code></pre> <p>will read a record of no more than 32768 characters from $fh. If you&#39;re not reading from a record-oriented file (or your OS doesn&#39;t have record-oriented files), then you&#39;ll likely get a full chunk of data with every read. If a record is larger than the record size you&#39;ve set, you&#39;ll get the record back in pieces. Trying to set the record size to zero or less is deprecated and will cause $/ to have the value of &quot;undef&quot;, which will cause reading in the (rest of the) whole file.</p> <p>As of 5.19.9 setting <code>$/</code> to any other form of reference will throw a fatal exception. This is in preparation for supporting new ways to set <code>$/</code> in the future.</p> <p>On VMS only, record reads bypass PerlIO layers and any associated buffering, so you must not mix record and non-record reads on the same filehandle. Record mode mixes with line mode only when the same buffering layer is in use for both modes.</p> <p>You cannot call <code>input_record_separator()</code> on a handle, only as a static method. See <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> <p>See also <a href="/5.39.2/perlport#Newlines">&quot;Newlines&quot; in perlport</a>. Also see <a href="#%24.">&quot;$.&quot;</a>.</p> <p>Mnemonic: / delimits line boundaries when quoting poetry.</p> </dd> <dt id="IO::Handle-&gt;output_record_separator(-EXPR-)"><a class="permalink" href="#IO::Handle-%3Eoutput_record_separator(-EXPR-)">#</a><a id="IO2"></a><a id="IO::Handle-output_record_separator-EXPR"></a>IO::Handle-&gt;output_record_separator( EXPR )</dt> <dd> </dd> <dt id="$OUTPUT_RECORD_SEPARATOR"><a class="permalink" href="#$OUTPUT_RECORD_SEPARATOR">#</a><a id="OUTPUT_RECORD_SEPARATOR"></a>$OUTPUT_RECORD_SEPARATOR</dt> <dd> </dd> <dt id="$ORS"><a class="permalink" href="#$ORS">#</a><a id="ORS"></a>$ORS</dt> <dd> </dd> <dt id="$\"><a class="permalink" href="#$%5C">#</a><a id="pod19"></a>$\ </dt> <dd> <p>The output record separator for the print operator. If defined, this value is printed after the last of print&#39;s arguments. Default is <code>undef</code>.</p> <p>You cannot call <code>output_record_separator()</code> on a handle, only as a static method. See <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> <p>Mnemonic: you set <code>$\</code> instead of adding &quot;\n&quot; at the end of the print. Also, it&#39;s just like <code>$/</code>, but it&#39;s what you get &quot;back&quot; from Perl.</p> </dd> <dt id="HANDLE-&gt;autoflush(-EXPR-)"><a class="permalink" href="#HANDLE-%3Eautoflush(-EXPR-)">#</a><a id="HANDLE1"></a><a id="HANDLE-autoflush-EXPR"></a>HANDLE-&gt;autoflush( EXPR )</dt> <dd> </dd> <dt id="$OUTPUT_AUTOFLUSH"><a class="permalink" href="#$OUTPUT_AUTOFLUSH">#</a><a id="OUTPUT_AUTOFLUSH"></a>$OUTPUT_AUTOFLUSH</dt> <dd> </dd> <dt id="$|"><a class="permalink" href="#$%7C">#</a><a id="pod20"></a>$| </dt> <dd> <p>If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; <code>$|</code> tells you only whether you&#39;ve asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under <b>rsh</b> and want to see the output as it&#39;s happening. This has no effect on input buffering. See <a href="/5.39.2/perlfunc#getc">&quot;getc&quot; in perlfunc</a> for that. See <a href="/5.39.2/perlfunc#select">&quot;select&quot; in perlfunc</a> on how to select the output channel. See also <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> <p>Mnemonic: when you want your pipes to be piping hot.</p> </dd> <dt id="${^LAST_FH}"><a class="permalink" href="#$%7B%5ELAST_FH%7D">#</a><a id="LAST_FH"></a>${^LAST_FH} </dt> <dd> <p>This read-only variable contains a reference to the last-read filehandle. This is set by <code>&lt;HANDLE&gt;</code>, <code>readline</code>, <code>tell</code>, <code>eof</code> and <code>seek</code>. This is the same handle that <code>$.</code> and <code>tell</code> and <code>eof</code> without arguments use. It is also the handle used when Perl appends &quot;, &lt;STDIN&gt; line 1&quot; to an error or warning message.</p> <p>This variable was added in Perl v5.18.0.</p> </dd> </dl> <h3 id="Variables-related-to-formats"><a class="permalink" href="#Variables-related-to-formats">#</a><a id="Variables2"></a>Variables related to formats</h3> <p>The special variables for formats are a subset of those for filehandles. See <a href="/5.39.2/perlform">perlform</a> for more information about Perl&#39;s formats.</p> <dl> <dt id="$ACCUMULATOR"><a class="permalink" href="#$ACCUMULATOR">#</a><a id="ACCUMULATOR"></a>$ACCUMULATOR</dt> <dd> </dd> <dt id="$^A"><a class="permalink" href="#$%5EA">#</a><a id="A"></a>$^A </dt> <dd> <p>The current value of the <code>write()</code> accumulator for <code>format()</code> lines. A format contains <code>formline()</code> calls that put their result into <code>$^A</code>. After calling its format, <code>write()</code> prints out the contents of <code>$^A</code> and empties. So you never really see the contents of <code>$^A</code> unless you call <code>formline()</code> yourself and then look at it. See <a href="/5.39.2/perlform">perlform</a> and <a href="/5.39.2/perlfunc#formline-PICTURE%2CLIST">&quot;formline PICTURE,LIST&quot; in perlfunc</a>.</p> </dd> <dt id="IO::Handle-&gt;format_formfeed(EXPR)"><a class="permalink" href="#IO::Handle-%3Eformat_formfeed(EXPR)">#</a><a id="IO3"></a><a id="IO::Handle-format_formfeed-EXPR"></a>IO::Handle-&gt;format_formfeed(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_FORMFEED"><a class="permalink" href="#$FORMAT_FORMFEED">#</a><a id="FORMAT_FORMFEED"></a>$FORMAT_FORMFEED</dt> <dd> </dd> <dt id="$^L"><a class="permalink" href="#$%5EL">#</a><a id="L"></a>$^L </dt> <dd> <p>What formats output as a form feed. The default is <code>\f</code>.</p> <p>You cannot call <code>format_formfeed()</code> on a handle, only as a static method. See <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> </dd> <dt id="HANDLE-&gt;format_page_number(EXPR)"><a class="permalink" href="#HANDLE-%3Eformat_page_number(EXPR)">#</a><a id="HANDLE2"></a><a id="HANDLE-format_page_number-EXPR"></a>HANDLE-&gt;format_page_number(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_PAGE_NUMBER"><a class="permalink" href="#$FORMAT_PAGE_NUMBER">#</a><a id="FORMAT_PAGE_NUMBER"></a>$FORMAT_PAGE_NUMBER</dt> <dd> </dd> <dt id="$%"><a class="permalink" href="#$%25">#</a><a id="pod21"></a>$% </dt> <dd> <p>The current page number of the currently selected output channel.</p> <p>Mnemonic: <code>%</code> is page number in <b>nroff</b>.</p> </dd> <dt id="HANDLE-&gt;format_lines_left(EXPR)"><a class="permalink" href="#HANDLE-%3Eformat_lines_left(EXPR)">#</a><a id="HANDLE3"></a><a id="HANDLE-format_lines_left-EXPR"></a>HANDLE-&gt;format_lines_left(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_LINES_LEFT"><a class="permalink" href="#$FORMAT_LINES_LEFT">#</a><a id="FORMAT_LINES_LEFT"></a>$FORMAT_LINES_LEFT</dt> <dd> </dd> <dt id="$-"><a class="permalink" href="#$-">#</a><a id="pod22"></a>$- </dt> <dd> <p>The number of lines left on the page of the currently selected output channel.</p> <p>Mnemonic: lines_on_page - lines_printed.</p> </dd> <dt id="IO::Handle-&gt;format_line_break_characters-EXPR"><a class="permalink" href="#IO::Handle-%3Eformat_line_break_characters-EXPR">#</a><a id="IO4"></a><a id="IO::Handle-format_line_break_characters-EXPR"></a>IO::Handle-&gt;format_line_break_characters EXPR</dt> <dd> </dd> <dt id="$FORMAT_LINE_BREAK_CHARACTERS"><a class="permalink" href="#$FORMAT_LINE_BREAK_CHARACTERS">#</a><a id="FORMAT_LINE_BREAK_CHARACTERS"></a>$FORMAT_LINE_BREAK_CHARACTERS</dt> <dd> </dd> <dt id="$:"><a class="permalink" href="#$:">#</a><a id="pod23"></a>$: </dt> <dd> <p>The current set of characters after which a string may be broken to fill continuation fields (starting with <code>^</code>) in a format. The default is <span style="white-space: nowrap;">&quot; \n-&quot;</span>, to break on a space, newline, or a hyphen.</p> <p>You cannot call <code>format_line_break_characters()</code> on a handle, only as a static method. See <a href="/5.39.2/IO::Handle">IO::Handle</a>.</p> <p>Mnemonic: a &quot;colon&quot; in poetry is a part of a line.</p> </dd> <dt id="HANDLE-&gt;format_lines_per_page(EXPR)"><a class="permalink" href="#HANDLE-%3Eformat_lines_per_page(EXPR)">#</a><a id="HANDLE4"></a><a id="HANDLE-format_lines_per_page-EXPR"></a>HANDLE-&gt;format_lines_per_page(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_LINES_PER_PAGE"><a class="permalink" href="#$FORMAT_LINES_PER_PAGE">#</a><a id="FORMAT_LINES_PER_PAGE"></a>$FORMAT_LINES_PER_PAGE</dt> <dd> </dd> <dt id="$="><a class="permalink" href="#$=">#</a><a id="pod24"></a>$= </dt> <dd> <p>The current page length (printable lines) of the currently selected output channel. The default is 60.</p> <p>Mnemonic: = has horizontal lines.</p> </dd> <dt id="HANDLE-&gt;format_top_name(EXPR)"><a class="permalink" href="#HANDLE-%3Eformat_top_name(EXPR)">#</a><a id="HANDLE5"></a><a id="HANDLE-format_top_name-EXPR"></a>HANDLE-&gt;format_top_name(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_TOP_NAME"><a class="permalink" href="#$FORMAT_TOP_NAME">#</a><a id="FORMAT_TOP_NAME"></a>$FORMAT_TOP_NAME</dt> <dd> </dd> <dt id="$^"><a class="permalink" href="#$%5E">#</a><a id="pod25"></a>$^ </dt> <dd> <p>The name of the current top-of-page format for the currently selected output channel. The default is the name of the filehandle with <code>_TOP</code> appended. For example, the default format top name for the <code>STDOUT</code> filehandle is <code>STDOUT_TOP</code>.</p> <p>Mnemonic: points to top of page.</p> </dd> <dt id="HANDLE-&gt;format_name(EXPR)"><a class="permalink" href="#HANDLE-%3Eformat_name(EXPR)">#</a><a id="HANDLE6"></a><a id="HANDLE-format_name-EXPR"></a>HANDLE-&gt;format_name(EXPR)</dt> <dd> </dd> <dt id="$FORMAT_NAME"><a class="permalink" href="#$FORMAT_NAME">#</a><a id="FORMAT_NAME"></a>$FORMAT_NAME</dt> <dd> </dd> <dt id="$~"><a class="permalink" href="#$~">#</a><a id="pod26"></a>$~ </dt> <dd> <p>The name of the current report format for the currently selected output channel. The default format name is the same as the filehandle name. For example, the default format name for the <code>STDOUT</code> filehandle is just <code>STDOUT</code>.</p> <p>Mnemonic: brother to <code>$^</code>.</p> </dd> </dl> <h2 id="Error-Variables"><a class="permalink" href="#Error-Variables">#</a><a id="Error"></a>Error Variables </h2> <p>The variables <code>$@</code>, <code>$!</code>, <code>$^E</code>, and <code>$?</code> contain information about different types of error conditions that may appear during execution of a Perl program. The variables are shown ordered by the &quot;distance&quot; between the subsystem which reported the error and the Perl process. They correspond to errors detected by the Perl interpreter, C library, operating system, or an external program, respectively.</p> <p>To illustrate the differences between these variables, consider the following Perl expression, which uses a single-quoted string. After execution of this statement, perl may have set all four special error variables:</p> <pre><code>eval q{ open my $pipe, &quot;/cdrom/install |&quot; or die $!; my @res = &lt;$pipe&gt;; close $pipe or die &quot;bad pipe: $?, $!&quot;; };</code></pre> <p>When perl executes the <code>eval()</code> expression, it translates the <code>open()</code>, <code>&lt;PIPE&gt;</code>, and <code>close</code> calls in the C run-time library and thence to the operating system kernel. perl sets <code>$!</code> to the C library&#39;s <code>errno</code> if one of these calls fails.</p> <p><code>$@</code> is set if the string to be <code>eval</code>-ed did not compile (this may happen if <code>open</code> or <code>close</code> were imported with bad prototypes), or if Perl code executed during evaluation <code>die()</code>d. In these cases the value of <code>$@</code> is the compile error, or the argument to <code>die</code> (which will interpolate <code>$!</code> and <code>$?</code>). (See also <a href="/5.39.2/Fatal">Fatal</a>, though.)</p> <p>Under a few operating systems, <code>$^E</code> may contain a more verbose error indicator, such as in this case, &quot;CDROM tray not closed.&quot; Systems that do not support extended error messages leave <code>$^E</code> the same as <code>$!</code>.</p> <p>Finally, <code>$?</code> may be set to a non-0 value if the external program <i>/cdrom/install</i> fails. The upper eight bits reflect specific error conditions encountered by the program (the program&#39;s <code>exit()</code> value). The lower eight bits reflect mode of failure, like signal death and core dump information. See <a href="http://man.he.net/man2/wait">wait(2)</a> for details. In contrast to <code>$!</code> and <code>$^E</code>, which are set only if an error condition is detected, the variable <code>$?</code> is set on each <code>wait</code> or pipe <code>close</code>, overwriting the old value. This is more like <code>$@</code>, which on every <code>eval()</code> is always set on failure and cleared on success.</p> <p>For more details, see the individual descriptions at <code>$@</code>, <code>$!</code>, <code>$^E</code>, and <code>$?</code>.</p> <dl> <dt id="${^CHILD_ERROR_NATIVE}"><a class="permalink" href="#$%7B%5ECHILD_ERROR_NATIVE%7D">#</a><a id="CHILD_ERROR_NATIVE"></a>${^CHILD_ERROR_NATIVE} </dt> <dd> <p>The native status returned by the last pipe close, backtick (<code>``</code>) command, successful call to <code>wait()</code> or <code>waitpid()</code>, or from the <code>system()</code> operator. On POSIX-like systems this value can be decoded with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, and WSTOPSIG functions provided by the <a href="/5.39.2/POSIX">POSIX</a> module.</p> <p>Under VMS this reflects the actual VMS exit status; i.e. it is the same as <code>$?</code> when the pragma <code>use vmsish &#39;status&#39;</code> is in effect.</p> <p>This variable was added in Perl v5.10.0.</p> </dd> <dt id="$EXTENDED_OS_ERROR"><a class="permalink" href="#$EXTENDED_OS_ERROR">#</a><a id="EXTENDED_OS_ERROR"></a>$EXTENDED_OS_ERROR</dt> <dd> </dd> <dt id="$^E"><a class="permalink" href="#$%5EE">#</a><a id="E"></a>$^E </dt> <dd> <p>Error information specific to the current operating system. At the moment, this differs from <code><a href="#%24!">&quot;$!&quot;</a></code> under only VMS, OS/2, and Win32 (and for MacPerl). On all other platforms, <code>$^E</code> is always just the same as <code>$!</code>.</p> <p>Under VMS, <code>$^E</code> provides the VMS status value from the last system error. This is more specific information about the last system error than that provided by <code>$!</code>. This is particularly important when <code>$!</code> is set to <b>EVMSERR</b>.</p> <p>Under OS/2, <code>$^E</code> is set to the error code of the last call to OS/2 API either via CRT, or directly from perl.</p> <p>Under Win32, <code>$^E</code> always returns the last error information reported by the Win32 call <code>GetLastError()</code> which describes the last error from within the Win32 API. Most Win32-specific code will report errors via <code>$^E</code>. ANSI C and Unix-like calls set <code>errno</code> and so most portable Perl code will report errors via <code>$!</code>.</p> <p>Caveats mentioned in the description of <code><a href="#%24!">&quot;$!&quot;</a></code> generally apply to <code>$^E</code>, also.</p> <p>This variable was added in Perl 5.003.</p> <p>Mnemonic: Extra error explanation.</p> </dd> <dt id="$EXCEPTIONS_BEING_CAUGHT"><a class="permalink" href="#$EXCEPTIONS_BEING_CAUGHT">#</a><a id="EXCEPTIONS_BEING_CAUGHT"></a>$EXCEPTIONS_BEING_CAUGHT</dt> <dd> </dd> <dt id="$^S"><a class="permalink" href="#$%5ES">#</a><a id="S"></a>$^S </dt> <dd> <p>Current state of the interpreter.</p> <pre><code class="plaintext">$^S State --------- ------------------------------------- undef Parsing module, eval, or main program true (1) Executing an eval or try block false (0) Otherwise</code></pre> <p>The first state may happen in <code>$SIG{__DIE__}</code> and <code>$SIG{__WARN__}</code> handlers.</p> <p>The English name $EXCEPTIONS_BEING_CAUGHT is slightly misleading, because the <code>undef</code> value does not indicate whether exceptions are being caught, since compilation of the main program does not catch exceptions.</p> <p>This variable was added in Perl 5.004.</p> </dd> <dt id="$WARNING"><a class="permalink" href="#$WARNING">#</a><a id="WARNING"></a>$WARNING</dt> <dd> </dd> <dt id="$^W"><a class="permalink" href="#$%5EW">#</a><a id="W"></a>$^W </dt> <dd> <p>The current value of the warning switch, initially true if <b>-w</b> was used, false otherwise, but directly modifiable.</p> <p>See also <a href="/5.39.2/warnings">warnings</a>.</p> <p>Mnemonic: related to the <b>-w</b> switch.</p> </dd> <dt id="${^WARNING_BITS}"><a class="permalink" href="#$%7B%5EWARNING_BITS%7D">#</a><a id="WARNING_BITS"></a>${^WARNING_BITS} </dt> <dd> <p>The current set of warning checks enabled by the <code>use warnings</code> pragma. It has the same scoping as the <code>$^H</code> and <code>%^H</code> variables. The exact values are considered internal to the <a href="/5.39.2/warnings">warnings</a> pragma and may change between versions of Perl.</p> <p>Each time a statement completes being compiled, the current value of <code>${^WARNING_BITS}</code> is stored with that statement, and can later be retrieved via <code>(caller($level))[9]</code>.</p> <p>This variable was added in Perl v5.6.0.</p> </dd> <dt id="$OS_ERROR"><a class="permalink" href="#$OS_ERROR">#</a><a id="OS_ERROR"></a>$OS_ERROR</dt> <dd> </dd> <dt id="$ERRNO"><a class="permalink" href="#$ERRNO">#</a><a id="ERRNO"></a>$ERRNO</dt> <dd> </dd> <dt id="$!"><a class="permalink" href="#$!">#</a><a id="pod27"></a>$! </dt> <dd> <p>When referenced, <code>$!</code> retrieves the current value of the C <code>errno</code> integer variable. If <code>$!</code> is assigned a numerical value, that value is stored in <code>errno</code>. When referenced as a string, <code>$!</code> yields the system error string corresponding to <code>errno</code>.</p> <p>Many system or library calls set <code>errno</code> if they fail, to indicate the cause of failure. They usually do <b>not</b> set <code>errno</code> to zero if they succeed and may set <code>errno</code> to a non-zero value on success. This means <code>errno</code>, hence <code>$!</code>, is meaningful only <i>immediately</i> after a <b>failure</b>:</p> <pre><code>if (open my $fh, &quot;&lt;&quot;, $filename) { # Here $! is meaningless. ... } else { # ONLY here is $! meaningful. ... # Already here $! might be meaningless. } # Since here we might have either success or failure, # $! is meaningless.</code></pre> <p>Here, <i>meaningless</i> means that <code>$!</code> may be unrelated to the outcome of the <code>open()</code> operator. Assignment to <code>$!</code> is similarly ephemeral. It can be used immediately before invoking the <code>die()</code> operator, to set the exit value, or to inspect the system error string corresponding to error <i>n</i>, or to restore <code>$!</code> to a meaningful state.</p> <p>Perl itself may set <code>errno</code> to a non-zero on failure even if no system call is performed.</p> <p>Mnemonic: What just went bang?</p> </dd> <dt id="%OS_ERROR"><a class="permalink" href="#%25OS_ERROR">#</a><a id="OS_ERROR1"></a>%OS_ERROR</dt> <dd> </dd> <dt id="%ERRNO"><a class="permalink" href="#%25ERRNO">#</a><a id="ERRNO1"></a>%ERRNO</dt> <dd> </dd> <dt id="%!"><a class="permalink" href="#%25!">#</a><a id="pod28"></a>%! </dt> <dd> <p>Each element of <code>%!</code> has a true value only if <code>$!</code> is set to that value. For example, <code>$!{ENOENT}</code> is true if and only if the current value of <code>$!</code> is <code>ENOENT</code>; that is, if the most recent error was &quot;No such file or directory&quot; (or its moral equivalent: not all operating systems give that exact error, and certainly not all languages). The specific true value is not guaranteed, but in the past has generally been the numeric value of <code>$!</code>. To check if a particular key is meaningful on your system, use <code>exists $!{the_key}</code>; for a list of legal keys, use <code>keys %!</code>. See <a href="/5.39.2/Errno">Errno</a> for more information, and also see <a href="#%24!">&quot;$!&quot;</a>.</p> <p>This variable was added in Perl 5.005.</p> </dd> <dt id="$CHILD_ERROR"><a class="permalink" href="#$CHILD_ERROR">#</a><a id="CHILD_ERROR"></a>$CHILD_ERROR</dt> <dd> </dd> <dt id="$?"><a class="permalink" href="#$?">#</a><a id="pod29"></a>$? </dt> <dd> <p>The status returned by the last pipe close, backtick (<code>``</code>) command, successful call to <code>wait()</code> or <code>waitpid()</code>, or from the <code>system()</code> operator. This is just the 16-bit status word returned by the traditional Unix <code>wait()</code> system call (or else is made up to look like it). Thus, the exit value of the subprocess is really (<code>$? &gt;&gt; 8</code>), and <code>$? &amp; 127</code> gives which signal, if any, the process died from, and <code>$? &amp; 128</code> reports whether there was a core dump.</p> <p>Additionally, if the <code>h_errno</code> variable is supported in C, its value is returned via <code>$?</code> if any <code>gethost*()</code> function fails.</p> <p>If you have installed a signal handler for <code>SIGCHLD</code>, the value of <code>$?</code> will usually be wrong outside that handler.</p> <p>Inside an <code>END</code> subroutine <code>$?</code> contains the value that is going to be given to <code>exit()</code>. You can modify <code>$?</code> in an <code>END</code> subroutine to change the exit status of your program. For example:</p> <pre><code>END { $? = 1 if $? == 255; # die would make it 255 }</code></pre> <p>Under VMS, the pragma <code>use vmsish &#39;status&#39;</code> makes <code>$?</code> reflect the actual VMS exit status, instead of the default emulation of POSIX status; see <a href="/5.39.2/perlvms#%24%3F">&quot;$?&quot; in perlvms</a> for details.</p> <p>Mnemonic: similar to <b>sh</b> and <b>ksh</b>.</p> </dd> <dt id="$EVAL_ERROR"><a class="permalink" href="#$EVAL_ERROR">#</a><a id="EVAL_ERROR"></a>$EVAL_ERROR</dt> <dd> </dd> <dt id="$@"><a class="permalink" href="#$@">#</a><a id="pod30"></a>$@ </dt> <dd> <p>The Perl error from the last <code>eval</code> operator, i.e. the last exception that was caught. For <code>eval BLOCK</code>, this is either a runtime error message or the string or reference <code>die</code> was called with. The <code>eval STRING</code> form also catches syntax errors and other compile time exceptions.</p> <p>If no error occurs, <code>eval</code> sets <code>$@</code> to the empty string.</p> <p>Warning messages are not collected in this variable. You can, however, set up a routine to process warnings by setting <code>$SIG{__WARN__}</code> as described in <a href="#%25SIG">&quot;%SIG&quot;</a>.</p> <p>Mnemonic: Where was the error &quot;at&quot;?</p> </dd> </dl> <h2 id="Variables-related-to-the-interpreter-state"><a class="permalink" href="#Variables-related-to-the-interpreter-state">#</a><a id="Variables3"></a>Variables related to the interpreter state</h2> <p>These variables provide information about the current interpreter state.</p> <dl> <dt id="$COMPILING"><a class="permalink" href="#$COMPILING">#</a><a id="COMPILING"></a>$COMPILING</dt> <dd> </dd> <dt id="$^C"><a class="permalink" href="#$%5EC">#</a><a id="C"></a>$^C </dt> <dd> <p>The current value of the flag associated with the <b>-c</b> switch. Mainly of use with <b>-MO=...</b> to allow code to alter its behavior when being compiled, such as for example to <code>AUTOLOAD</code> at compile time rather than normal, deferred loading. Setting <code>$^C = 1</code> is similar to calling <code>B::minus_c</code>.</p> <p>This variable was added in Perl v5.6.0.</p> </dd> <dt id="$DEBUGGING"><a class="permalink" href="#$DEBUGGING">#</a><a id="DEBUGGING"></a>$DEBUGGING</dt> <dd> </dd> <dt id="$^D"><a class="permalink" href="#$%5ED">#</a><a id="D"></a>$^D </dt> <dd> <p>The current value of the debugging flags. May be read or set. Like its <a href="/5.39.2/perlrun#-Dletters">command-line equivalent</a>, you can use numeric or symbolic values, e.g. <code>$^D = 10</code> or <code>$^D = &quot;st&quot;</code>. See <a href="/5.39.2/perlrun#-Dnumber">&quot;<b>-D</b><i>number</i>&quot; in perlrun</a>. The contents of this variable also affects the debugger operation. See <a href="/5.39.2/perldebguts#Debugger-Internals">&quot;Debugger Internals&quot; in perldebguts</a>.</p> <p>Mnemonic: value of <b>-D</b> switch.</p> </dd> <dt id="${^GLOBAL_PHASE}"><a class="permalink" href="#$%7B%5EGLOBAL_PHASE%7D">#</a><a id="GLOBAL_PHASE"></a>${^GLOBAL_PHASE} </dt> <dd> <p>The current phase of the perl interpreter.</p> <p>Possible values are:</p> <dl> <dt id="CONSTRUCT"><a class="permalink" href="#CONSTRUCT">#</a>CONSTRUCT</dt> <dd> <p>The <code>PerlInterpreter*</code> is being constructed via <code>perl_construct</code>. This value is mostly there for completeness and for use via the underlying C variable <code>PL_phase</code>. It&#39;s not really possible for Perl code to be executed unless construction of the interpreter is finished.</p> </dd> <dt id="START"><a class="permalink" href="#START">#</a>START</dt> <dd> <p>This is the global compile-time. That includes, basically, every <code>BEGIN</code> block executed directly or indirectly from during the compile-time of the top-level program.</p> <p>This phase is not called &quot;BEGIN&quot; to avoid confusion with <code>BEGIN</code>-blocks, as those are executed during compile-time of any compilation unit, not just the top-level program. A new, localised compile-time entered at run-time, for example by constructs as <code>eval &quot;use SomeModule&quot;</code> are not global interpreter phases, and therefore aren&#39;t reflected by <code>${^GLOBAL_PHASE}</code>.</p> </dd> <dt id="CHECK"><a class="permalink" href="#CHECK">#</a>CHECK</dt> <dd> <p>Execution of any <code>CHECK</code> blocks.</p> </dd> <dt id="INIT"><a class="permalink" href="#INIT">#</a>INIT</dt> <dd> <p>Similar to &quot;CHECK&quot;, but for <code>INIT</code>-blocks, not <code>CHECK</code> blocks.</p> </dd> <dt id="RUN"><a class="permalink" href="#RUN">#</a>RUN</dt> <dd> <p>The main run-time, i.e. the execution of <code>PL_main_root</code>.</p> </dd> <dt id="END"><a class="permalink" href="#END">#</a>END</dt> <dd> <p>Execution of any <code>END</code> blocks.</p> </dd> <dt id="DESTRUCT"><a class="permalink" href="#DESTRUCT">#</a>DESTRUCT</dt> <dd> <p>Global destruction.</p> </dd> </dl> <p>Also note that there&#39;s no value for UNITCHECK-blocks. That&#39;s because those are run for each compilation unit individually, and therefore is not a global interpreter phase.</p> <p>Not every program has to go through each of the possible phases, but transition from one phase to another can only happen in the order described in the above list.</p> <p>An example of all of the phases Perl code can see:</p> <pre><code>BEGIN { print &quot;compile-time: ${^GLOBAL_PHASE}\n&quot; } INIT { print &quot;init-time: ${^GLOBAL_PHASE}\n&quot; } CHECK { print &quot;check-time: ${^GLOBAL_PHASE}\n&quot; } { package Print::Phase; sub new { my ($class, $time) = @_; return bless \$time, $class; } sub DESTROY { my $self = shift; print &quot;$$self: ${^GLOBAL_PHASE}\n&quot;; } } print &quot;run-time: ${^GLOBAL_PHASE}\n&quot;; my $runtime = Print::Phase-&gt;new( &quot;lexical variables are garbage collected before END&quot; ); END { print &quot;end-time: ${^GLOBAL_PHASE}\n&quot; } our $destruct = Print::Phase-&gt;new( &quot;package variables are garbage collected after END&quot; );</code></pre> <p>This will print out</p> <pre><code class="plaintext">compile-time: START check-time: CHECK init-time: INIT run-time: RUN lexical variables are garbage collected before END: RUN end-time: END package variables are garbage collected after END: DESTRUCT</code></pre> <p>This variable was added in Perl 5.14.0.</p> </dd> <dt id="$^H"><a class="permalink" href="#$%5EH">#</a><a id="H"></a>$^H </dt> <dd> <p>WARNING: This variable is strictly for internal use only. Its availability, behavior, and contents are subject to change without notice.</p> <p>This variable contains compile-time hints for the Perl interpreter. At the end of compilation of a BLOCK the value of this variable is restored to the value when the interpreter started to compile the BLOCK.</p> <p>Each time a statement completes being compiled, the current value of <code>$^H</code> is stored with that statement, and can later be retrieved via <code>(caller($level))[8]</code>. See <a href="/5.39.2/perlfunc#caller-EXPR">&quot;caller EXPR&quot; in perlfunc</a>.</p> <p>When perl begins to parse any block construct that provides a lexical scope (e.g., eval body, required file, subroutine body, loop body, or conditional block), the existing value of <code>$^H</code> is saved, but its value is left unchanged. When the compilation of the block is completed, it regains the saved value. Between the points where its value is saved and restored, code that executes within BEGIN blocks is free to change the value of <code>$^H</code>.</p> <p>This behavior provides the semantic of lexical scoping, and is used in, for instance, the <code>use strict</code> pragma.</p> <p>The contents should be an integer; different bits of it are used for different pragmatic flags. Here&#39;s an example:</p> <pre><code>sub add_100 { $^H |= 0x100 } sub foo { BEGIN { add_100() } bar-&gt;baz($boon); }</code></pre> <p>Consider what happens during execution of the BEGIN block. At this point the BEGIN block has already been compiled, but the body of <code>foo()</code> is still being compiled. The new value of <code>$^H</code> will therefore be visible only while the body of <code>foo()</code> is being compiled.</p> <p>Substitution of <code>BEGIN { add_100() }</code> block with:</p> <pre><code>BEGIN { require strict; strict-&gt;import(&#39;vars&#39;) }</code></pre> <p>demonstrates how <code>use strict &#39;vars&#39;</code> is implemented. Here&#39;s a conditional version of the same lexical pragma:</p> <pre><code>BEGIN { require strict; strict-&gt;import(&#39;vars&#39;) if $condition }</code></pre> <p>This variable was added in Perl 5.003.</p> </dd> <dt id="%^H"><a class="permalink" href="#%25%5EH">#</a><a id="H1"></a>%^H </dt> <dd> <p>The <code>%^H</code> hash provides the same scoping semantics as <a href="#%24%5EH"><code>$^H</code></a>. This makes it useful for implementing lexically scoped pragmas. See <a href="/5.39.2/perlpragma">perlpragma</a>. All the entries are stringified when accessed at runtime, so only simple values can be accommodated. This means no references to objects, for example.</p> <p>Each time a statement completes being compiled, the current value of <code>%^H</code> is stored with that statement, and can later be retrieved via <code>(caller($level))[10]</code>. See <a href="/5.39.2/perlfunc#caller-EXPR">&quot;caller EXPR&quot; in perlfunc</a>.</p> <p>When putting items into <code>%^H</code>, in order to avoid conflicting with other users of the hash there is a convention regarding which keys to use. A module should use only keys that begin with the module&#39;s name (the name of its main package) and a &quot;/&quot; character. For example, a module <code>Foo::Bar</code> should use keys such as <code>Foo::Bar/baz</code>.</p> <p>This variable was added in Perl v5.6.0.</p> </dd> <dt id="${^OPEN}"><a class="permalink" href="#$%7B%5EOPEN%7D">#</a><a id="OPEN"></a>${^OPEN} </dt> <dd> <p>An internal variable used by <a href="/5.39.2/PerlIO">PerlIO</a>. A string in two parts, separated by a <code>\0</code> byte, the first part describes the input layers, the second part describes the output layers.</p> <p>This is the mechanism that applies the lexical effects of the <a href="/5.39.2/open">open</a> pragma, and the main program scope effects of the <code>io</code> or <code>D</code> options for the <a href="/5.39.2/perlrun#-C-%5Bnumber%2Flist%5D">-C command-line switch</a> and <a href="/5.39.2/perlrun#PERL_UNICODE">PERL_UNICODE environment variable</a>.</p> <p>The functions <code>accept()</code>, <code>open()</code>, <code>pipe()</code>, <code>readpipe()</code> (as well as the related <code>qx</code> and <code>`STRING`</code> operators), <code>socket()</code>, <code>socketpair()</code>, and <code>sysopen()</code> are affected by the lexical value of this variable. The implicit <a href="#ARGV">&quot;ARGV&quot;</a> handle opened by <code>readline()</code> (or the related <code>&lt;&gt;</code> and <code>&lt;&lt;&gt;&gt;</code> operators) on passed filenames is also affected (but not if it opens <code>STDIN</code>). If this variable is not set, these functions will set the default layers as described in <a href="/5.39.2/PerlIO#Defaults-and-how-to-override-them">&quot;Defaults and how to override them&quot; in PerlIO</a>.</p> <p><code>open()</code> ignores this variable (and the default layers) when called with 3 arguments and explicit layers are specified. Indirect calls to these functions via modules like <a href="/5.39.2/IO::Handle">IO::Handle</a> are not affected as they occur in a different lexical scope. Directory handles such as opened by <code>opendir()</code> are not currently affected.</p> <p>This variable was added in Perl v5.8.0.</p> </dd> <dt id="$PERLDB"><a class="permalink" href="#$PERLDB">#</a><a id="PERLDB"></a>$PERLDB</dt> <dd> </dd> <dt id="$^P"><a class="permalink" href="#$%5EP">#</a><a id="P"></a>$^P </dt> <dd> <p>The internal variable for debugging support. The meanings of the various bits are subject to change, but currently indicate:</p> <dl> <dt id="0x01"><a class="permalink" href="#0x01">#</a><a id="x01"></a>0x01</dt> <dd> <p>Debug subroutine enter/exit.</p> </dd> <dt id="0x02"><a class="permalink" href="#0x02">#</a><a id="x02"></a>0x02</dt> <dd> <p>Line-by-line debugging. Causes <code>DB::DB()</code> subroutine to be called for each statement executed. Also causes saving source code lines (like 0x400).</p> </dd> <dt id="0x04"><a class="permalink" href="#0x04">#</a><a id="x04"></a>0x04</dt> <dd> <p>Switch off optimizations.</p> </dd> <dt id="0x08"><a class="permalink" href="#0x08">#</a><a id="x08"></a>0x08</dt> <dd> <p>Preserve more data for future interactive inspections.</p> </dd> <dt id="0x10"><a class="permalink" href="#0x10">#</a><a id="x10"></a>0x10</dt> <dd> <p>Keep info about source lines on which a subroutine is defined.</p> </dd> <dt id="0x20"><a class="permalink" href="#0x20">#</a><a id="x20"></a>0x20</dt> <dd> <p>Start with single-step on.</p> </dd> <dt id="0x40"><a class="permalink" href="#0x40">#</a><a id="x40"></a>0x40</dt> <dd> <p>Use subroutine address instead of name when reporting.</p> </dd> <dt id="0x80"><a class="permalink" href="#0x80">#</a><a id="x80"></a>0x80</dt> <dd> <p>Report <code>goto &amp;subroutine</code> as well.</p> </dd> <dt id="0x100"><a class="permalink" href="#0x100">#</a><a id="x100"></a>0x100</dt> <dd> <p>Provide informative &quot;file&quot; names for evals based on the place they were compiled.</p> </dd> <dt id="0x200"><a class="permalink" href="#0x200">#</a><a id="x200"></a>0x200</dt> <dd> <p>Provide informative names to anonymous subroutines based on the place they were compiled.</p> </dd> <dt id="0x400"><a class="permalink" href="#0x400">#</a><a id="x400"></a>0x400</dt> <dd> <p>Save source code lines into <code>@{&quot;_&lt;$filename&quot;}</code>.</p> </dd> <dt id="0x800"><a class="permalink" href="#0x800">#</a><a id="x800"></a>0x800</dt> <dd> <p>When saving source, include evals that generate no subroutines.</p> </dd> <dt id="0x1000"><a class="permalink" href="#0x1000">#</a><a id="x1000"></a>0x1000</dt> <dd> <p>When saving source, include source that did not compile.</p> </dd> </dl> <p>Some bits may be relevant at compile-time only, some at run-time only. This is a new mechanism and the details may change. See also <a href="/5.39.2/perldebguts">perldebguts</a>.</p> </dd> <dt id="${^TAINT}"><a class="permalink" href="#$%7B%5ETAINT%7D">#</a><a id="TAINT"></a>${^TAINT} </dt> <dd> <p>Reflects if taint mode is on or off. 1 for on (the program was run with <b>-T</b>), 0 for off, -1 when only taint warnings are enabled (i.e. with <b>-t</b> or <b>-TU</b>).</p> <p>Note: if your perl was built without taint support (see <a href="/5.39.2/perlsec">perlsec</a>), then <code>${^TAINT}</code> will always be 0, even if the program was run with <b>-T</b>).</p> <p>This variable is read-only.</p> <p>This variable was added in Perl v5.8.0.</p> </dd> <dt id="${^SAFE_LOCALES}"><a class="permalink" href="#$%7B%5ESAFE_LOCALES%7D">#</a><a id="SAFE_LOCALES"></a>${^SAFE_LOCALES} </dt> <dd> <p>Reflects if safe locale operations are available to this perl (when the value is 1) or not (the value is 0). This variable is always 1 if the perl has been compiled without threads. It is also 1 if this perl is using thread-safe locale operations. Note that an individual thread may choose to use the global locale (generally unsafe) by calling <a href="/5.39.2/perlapi#switch_to_global_locale">&quot;switch_to_global_locale&quot; in perlapi</a>. This variable currently is still set to 1 in such threads.</p> <p>This variable is read-only.</p> <p>This variable was added in Perl v5.28.0.</p> </dd> <dt id="${^UNICODE}"><a class="permalink" href="#$%7B%5EUNICODE%7D">#</a><a id="UNICODE"></a>${^UNICODE} </dt> <dd> <p>Reflects certain Unicode settings of Perl. See <a href="/5.39.2/perlrun#-C-%5Bnumber%2Flist%5D">perlrun</a> documentation for the <code>-C</code> switch for more information about the possible values.</p> <p>This variable is set during Perl startup and is thereafter read-only.</p> <p>This variable was added in Perl v5.8.2.</p> </dd> <dt id="${^UTF8CACHE}"><a class="permalink" href="#$%7B%5EUTF8CACHE%7D">#</a><a id="UTF8CACHE"></a>${^UTF8CACHE} </dt> <dd> <p>This variable controls the state of the internal UTF-8 offset caching code. 1 for on (the default), 0 for off, -1 to debug the caching code by checking all its results against linear scans, and panicking on any discrepancy.</p> <p>This variable was added in Perl v5.8.9. It is subject to change or removal without notice, but is currently used to avoid recalculating the boundaries of multi-byte UTF-8-encoded characters.</p> </dd> <dt id="${^UTF8LOCALE}"><a class="permalink" href="#$%7B%5EUTF8LOCALE%7D">#</a><a id="UTF8LOCALE"></a>${^UTF8LOCALE} </dt> <dd> <p>This variable indicates whether a UTF-8 locale was detected by perl at startup. This information is used by perl when it&#39;s in adjust-utf8ness-to-locale mode (as when run with the <code>-CL</code> command-line switch); see <a href="/5.39.2/perlrun#-C-%5Bnumber%2Flist%5D">perlrun</a> for more info on this.</p> <p>This variable was added in Perl v5.8.8.</p> </dd> </dl> <h2 id="Deprecated-and-removed-variables"><a class="permalink" href="#Deprecated-and-removed-variables">#</a><a id="Deprecated"></a>Deprecated and removed variables</h2> <p>Deprecating a variable announces the intent of the perl maintainers to eventually remove the variable from the language. It may still be available despite its status. Using a deprecated variable triggers a warning.</p> <p>Once a variable is removed, its use triggers an error telling you the variable is unsupported.</p> <p>See <a href="/5.39.2/perldiag">perldiag</a> for details about error messages.</p> <dl> <dt id="$#"><a class="permalink" href="#$%23">#</a><a id="pod31"></a>$# </dt> <dd> <p><code>$#</code> was a variable that could be used to format printed numbers. After a deprecation cycle, its magic was removed in Perl v5.10.0 and using it now triggers a warning: <code>$# is no longer supported</code>.</p> <p>This is not the sigil you use in front of an array name to get the last index, like <code>$#array</code>. That&#39;s still how you get the last index of an array in Perl. The two have nothing to do with each other.</p> <p>Deprecated in Perl 5.</p> <p>Removed in Perl v5.10.0.</p> </dd> <dt id="$*"><a class="permalink" href="#$*">#</a><a id="pod32"></a>$* </dt> <dd> <p><code>$*</code> was a variable that you could use to enable multiline matching. After a deprecation cycle, its magic was removed in Perl v5.10.0. Using it now triggers a warning: <code>$* is no longer supported</code>. You should use the <code>/s</code> and <code>/m</code> regexp modifiers instead.</p> <p>Deprecated in Perl 5.</p> <p>Removed in Perl v5.10.0.</p> </dd> <dt id="$["><a class="permalink" href="#$%5B">#</a><a id="pod33"></a>$[ </dt> <dd> <p>This variable stores the index of the first element in an array, and of the first character in a substring. The default is 0, but you could theoretically set it to 1 to make Perl behave more like <b>awk</b> (or Fortran) when subscripting and when evaluating the index() and substr() functions.</p> <p>As of release 5 of Perl, assignment to <code>$[</code> is treated as a compiler directive, and cannot influence the behavior of any other file. (That&#39;s why you can only assign compile-time constants to it.) Its use is highly discouraged.</p> <p>Prior to Perl v5.10.0, assignment to <code>$[</code> could be seen from outer lexical scopes in the same file, unlike other compile-time directives (such as <a href="/5.39.2/strict">strict</a>). Using local() on it would bind its value strictly to a lexical block. Now it is always lexically scoped.</p> <p>As of Perl v5.16.0, it is implemented by the <a href="/5.39.2/arybase">arybase</a> module.</p> <p>As of Perl v5.30.0, or under <code>use v5.16</code>, or <code>no feature &quot;array_base&quot;</code>, <code>$[</code> no longer has any effect, and always contains 0. Assigning 0 to it is permitted, but any other value will produce an error.</p> <p>Mnemonic: [ begins subscripts.</p> <p>Deprecated in Perl v5.12.0.</p> </dd> <dt id="${^ENCODING}"><a class="permalink" href="#$%7B%5EENCODING%7D">#</a><a id="ENCODING"></a>${^ENCODING} </dt> <dd> <p>This variable is no longer supported.</p> <p>It used to hold the <i>object reference</i> to the <code>Encode</code> object that was used to convert the source code to Unicode.</p> <p>Its purpose was to allow your non-ASCII Perl scripts not to have to be written in UTF-8; this was useful before editors that worked on UTF-8 encoded text were common, but that was long ago. It caused problems, such as affecting the operation of other modules that weren&#39;t expecting it, causing general mayhem.</p> <p>If you need something like this functionality, it is recommended that use you a simple source filter, such as <a href="/5.39.2/Filter::Encoding">Filter::Encoding</a>.</p> <p>If you are coming here because code of yours is being adversely affected by someone&#39;s use of this variable, you can usually work around it by doing this:</p> <pre><code>local ${^ENCODING};</code></pre> <p>near the beginning of the functions that are getting broken. This undefines the variable during the scope of execution of the including function.</p> <p>This variable was added in Perl 5.8.2 and removed in 5.26.0. Setting it to anything other than <code>undef</code> was made fatal in Perl 5.28.0.</p> </dd> <dt id="${^WIN32_SLOPPY_STAT}"><a class="permalink" href="#$%7B%5EWIN32_SLOPPY_STAT%7D">#</a><a id="WIN32_SLOPPY_STAT"></a>${^WIN32_SLOPPY_STAT} </dt> <dd> <p>This variable no longer has any function.</p> <p>This variable was added in Perl v5.10.0 and removed in Perl v5.34.0.</p> </dd> </dl> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10