CINXE.COM
perlrun - how to execute the Perl interpreter - 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>perlrun - how to execute the Perl interpreter - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/perlrun"> <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.8.4</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/perlrun">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.0/perlrun">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.2/perlrun">5.38.2</a> <a class="dropdown-item" href="/5.38.1/perlrun">5.38.1</a> <a class="dropdown-item" href="/5.38.0/perlrun">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/perlrun">5.36.3</a> <a class="dropdown-item" href="/5.36.2/perlrun">5.36.2</a> <a class="dropdown-item" href="/5.36.1/perlrun">5.36.1</a> <a class="dropdown-item" href="/5.36.0/perlrun">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/perlrun">5.34.3</a> <a class="dropdown-item" href="/5.34.2/perlrun">5.34.2</a> <a class="dropdown-item" href="/5.34.1/perlrun">5.34.1</a> <a class="dropdown-item" href="/5.34.0/perlrun">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/perlrun">5.32.1</a> <a class="dropdown-item" href="/5.32.0/perlrun">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/perlrun">5.30.3</a> <a class="dropdown-item" href="/5.30.2/perlrun">5.30.2</a> <a class="dropdown-item" href="/5.30.1/perlrun">5.30.1</a> <a class="dropdown-item" href="/5.30.0/perlrun">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/perlrun">5.28.3</a> <a class="dropdown-item" href="/5.28.2/perlrun">5.28.2</a> <a class="dropdown-item" href="/5.28.1/perlrun">5.28.1</a> <a class="dropdown-item" href="/5.28.0/perlrun">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/perlrun">5.26.3</a> <a class="dropdown-item" href="/5.26.2/perlrun">5.26.2</a> <a class="dropdown-item" href="/5.26.1/perlrun">5.26.1</a> <a class="dropdown-item" href="/5.26.0/perlrun">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/perlrun">5.24.4</a> <a class="dropdown-item" href="/5.24.3/perlrun">5.24.3</a> <a class="dropdown-item" href="/5.24.2/perlrun">5.24.2</a> <a class="dropdown-item" href="/5.24.1/perlrun">5.24.1</a> <a class="dropdown-item" href="/5.24.0/perlrun">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/perlrun">5.22.4</a> <a class="dropdown-item" href="/5.22.3/perlrun">5.22.3</a> <a class="dropdown-item" href="/5.22.2/perlrun">5.22.2</a> <a class="dropdown-item" href="/5.22.1/perlrun">5.22.1</a> <a class="dropdown-item" href="/5.22.0/perlrun">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/perlrun">5.20.3</a> <a class="dropdown-item" href="/5.20.2/perlrun">5.20.2</a> <a class="dropdown-item" href="/5.20.1/perlrun">5.20.1</a> <a class="dropdown-item" href="/5.20.0/perlrun">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/perlrun">5.18.4</a> <a class="dropdown-item" href="/5.18.3/perlrun">5.18.3</a> <a class="dropdown-item" href="/5.18.2/perlrun">5.18.2</a> <a class="dropdown-item" href="/5.18.1/perlrun">5.18.1</a> <a class="dropdown-item" href="/5.18.0/perlrun">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/perlrun">5.16.3</a> <a class="dropdown-item" href="/5.16.2/perlrun">5.16.2</a> <a class="dropdown-item" href="/5.16.1/perlrun">5.16.1</a> <a class="dropdown-item" href="/5.16.0/perlrun">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/perlrun">5.14.4</a> <a class="dropdown-item" href="/5.14.3/perlrun">5.14.3</a> <a class="dropdown-item" href="/5.14.2/perlrun">5.14.2</a> <a class="dropdown-item" href="/5.14.1/perlrun">5.14.1</a> <a class="dropdown-item" href="/5.14.0/perlrun">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/perlrun">5.12.5</a> <a class="dropdown-item" href="/5.12.4/perlrun">5.12.4</a> <a class="dropdown-item" href="/5.12.3/perlrun">5.12.3</a> <a class="dropdown-item" href="/5.12.2/perlrun">5.12.2</a> <a class="dropdown-item" href="/5.12.1/perlrun">5.12.1</a> <a class="dropdown-item" href="/5.12.0/perlrun">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/perlrun">5.10.1</a> <a class="dropdown-item" href="/5.10.0/perlrun">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/perlrun">5.8.9</a> <a class="dropdown-item" href="/5.8.8/perlrun">5.8.8</a> <a class="dropdown-item" href="/5.8.7/perlrun">5.8.7</a> <a class="dropdown-item" href="/5.8.6/perlrun">5.8.6</a> <a class="dropdown-item" href="/5.8.5/perlrun">5.8.5</a> <a class="dropdown-item active" href="/5.8.4/perlrun">5.8.4</a> <a class="dropdown-item" href="/5.8.3/perlrun">5.8.3</a> <a class="dropdown-item" href="/5.8.2/perlrun">5.8.2</a> <a class="dropdown-item" href="/5.8.1/perlrun">5.8.1</a> <a class="dropdown-item" href="/5.8.0/perlrun">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/perlrun">5.6.2</a> <a class="dropdown-item" href="/5.6.1/perlrun">5.6.1</a> <a class="dropdown-item" href="/5.6.0/perlrun">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/perlrun">5.005_04</a> <a class="dropdown-item" href="/5.005_03/perlrun">5.005_03</a> <a class="dropdown-item" href="/5.005_02/perlrun">5.005_02</a> <a class="dropdown-item" href="/5.005_01/perlrun">5.005_01</a> <a class="dropdown-item" href="/5.005/perlrun">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/perlrun">blead</a> <a class="dropdown-item" href="/5.41.6/perlrun">5.41.6</a> <a class="dropdown-item" href="/5.41.5/perlrun">5.41.5</a> <a class="dropdown-item" href="/5.41.4/perlrun">5.41.4</a> <a class="dropdown-item" href="/5.41.3/perlrun">5.41.3</a> <a class="dropdown-item" href="/5.41.2/perlrun">5.41.2</a> <a class="dropdown-item" href="/5.41.1/perlrun">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.0-RC2/perlrun">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/perlrun">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/perlrun">5.39.10</a> <a class="dropdown-item" href="/5.39.9/perlrun">5.39.9</a> <a class="dropdown-item" href="/5.39.8/perlrun">5.39.8</a> <a class="dropdown-item" href="/5.39.7/perlrun">5.39.7</a> <a class="dropdown-item" href="/5.39.6/perlrun">5.39.6</a> <a class="dropdown-item" href="/5.39.5/perlrun">5.39.5</a> <a class="dropdown-item" href="/5.39.4/perlrun">5.39.4</a> <a class="dropdown-item" href="/5.39.3/perlrun">5.39.3</a> <a class="dropdown-item" href="/5.39.2/perlrun">5.39.2</a> <a class="dropdown-item" href="/5.39.1/perlrun">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.8.4/perl">Perl</a> <a class="dropdown-item" href="/5.8.4/perlintro">Intro</a> <a class="dropdown-item" href="/5.8.4/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.8.4/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.8.4/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.4/perlop">Operators</a> <a class="dropdown-item" href="/5.8.4/functions">Functions</a> <a class="dropdown-item" href="/5.8.4/variables">Variables</a> <a class="dropdown-item" href="/5.8.4/modules">Modules</a> <a class="dropdown-item" href="/5.8.4/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.4/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.8.4/perlcommunity">Community</a> <a class="dropdown-item" href="/5.8.4/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.8.4/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.8.4/perlrun">perlrun</a> <div id="more"> (<a href="/5.8.4/perlrun.txt">source</a>, <a href="https://metacpan.org/pod/perlrun">CPAN</a>) </div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.8.4. <a href="/perlrun">View the latest version</a> </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="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> <ul> <li> <a class="text-decoration-none" href="#%23!-and-quoting-on-non-Unix-systems">#! and quoting on non-Unix systems</a> </li> <li> <a class="text-decoration-none" href="#Location-of-Perl">Location of Perl</a> </li> <li> <a class="text-decoration-none" href="#Command-Switches">Command Switches</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#ENVIRONMENT">ENVIRONMENT</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>perlrun - how to execute the Perl interpreter</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <p><b>perl</b> <span style="white-space: nowrap;">[ <b>-sTtuUWX</b> ]</span> <span style="white-space: nowrap;">[ <b>-hv</b> ] [ <b>-V</b>[:<i>configvar</i>] ]</span> <span style="white-space: nowrap;">[ <b>-cw</b> ] [ <b>-d</b>[:<i>debugger</i>] ] [ <b>-D</b>[<i>number/list</i>] ]</span> <span style="white-space: nowrap;">[ <b>-pna</b> ] [ <b>-F</b><i>pattern</i> ] [ <b>-l</b>[<i>octal</i>] ] [ <b>-0</b>[<i>octal/hexadecimal</i>] ]</span> <span style="white-space: nowrap;">[ <b>-I</b><i>dir</i> ] [ <b>-m</b>[<b>-</b>]<i>module</i> ] [ <b>-M</b>[<b>-</b>]<i>'module...'</i> ]</span> <span style="white-space: nowrap;">[ <b>-P</b> ]</span> <span style="white-space: nowrap;">[ <b>-S</b> ]</span> <span style="white-space: nowrap;">[ <b>-x</b>[<i>dir</i>] ]</span> <span style="white-space: nowrap;">[ <b>-i</b>[<i>extension</i>] ]</span> <span style="white-space: nowrap;">[ <b>-e</b> <i>'command'</i> ] [ <b>--</b> ] [ <i>programfile</i> ] [ <i>argument</i> ]...</span> <span style="white-space: nowrap;">[ <b>-C [<i>number/list</i>] </b>]</span> ]></p> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>The normal way to run a Perl program is by making it directly executable, or else by passing the name of the source file as an argument on the command line. (An interactive Perl environment is also possible--see <a href="/5.8.4/perldebug">perldebug</a> for details on how to do that.) Upon startup, Perl looks for your program in one of the following places:</p> <ol> <li><p>Specified line by line via <b>-e</b> switches on the command line.</p> </li> <li><p>Contained in the file specified by the first filename on the command line. (Note that systems supporting the #! notation invoke interpreters this way. See <a href="#Location-of-Perl">"Location of Perl"</a>.)</p> </li> <li><p>Passed in implicitly via standard input. This works only if there are no filename arguments--to pass arguments to a STDIN-read program you must explicitly specify a "-" for the program name.</p> </li> </ol> <p>With methods 2 and 3, Perl starts parsing the input file from the beginning, unless you've specified a <b>-x</b> switch, in which case it scans for the first line starting with #! and containing the word "perl", and starts there instead. This is useful for running a program embedded in a larger message. (In this case you would indicate the end of the program using the <code>__END__</code> token.)</p> <p>The #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behavior regardless of how Perl was invoked, even if <b>-x</b> was used to find the beginning of the program.</p> <p>Because historically some operating systems silently chopped off kernel interpretation of the #! line after 32 characters, some switches may be passed in on the command line, and some may not; you could even get a "-" without its letter, if you're not careful. You probably want to make sure that all your switches fall either before or after that 32-character boundary. Most switches don't actually care if they're processed redundantly, but getting a "-" instead of a complete switch could cause Perl to try to execute standard input instead of your program. And a partial <b>-I</b> switch could also cause odd results.</p> <p>Some switches do care if they are processed twice, for instance combinations of <b>-l</b> and <b>-0</b>. Either put all the switches after the 32-character boundary (if applicable), or replace the use of <b>-0</b><i>digits</i> by <code>BEGIN{ $/ = "\0digits"; }</code>.</p> <p>Parsing of the #! switches starts wherever "perl" is mentioned in the line. The sequences "-*" and "- " are specifically ignored so that you could, if you were so inclined, say</p> <pre><code>#!/bin/sh -- # -*- perl -*- -p eval 'exec perl -wS $0 ${1+"$@"}' if $running_under_some_shell;</code></pre> <p>to let Perl see the <b>-p</b> switch.</p> <p>A similar trick involves the <b>env</b> program, if you have it.</p> <pre><code class="plaintext">#!/usr/bin/env perl</code></pre> <p>The examples above use a relative path to the perl interpreter, getting whatever version is first in the user's path. If you want a specific version of Perl, say, perl5.005_57, you should place that directly in the #! line's path.</p> <p>If the #! line does not contain the word "perl", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL is <i>/usr/bin/perl</i>, and Perl will then dispatch the program to the correct interpreter for them.</p> <p>After locating your program, Perl compiles the entire program to an internal form. If there are any compilation errors, execution of the program is not attempted. (This is unlike the typical shell script, which might run part-way through before finding a syntax error.)</p> <p>If the program is syntactically correct, it is executed. If the program runs off the end without hitting an exit() or die() operator, an implicit <code>exit(0)</code> is provided to indicate successful completion.</p> <h2 id="#!-and-quoting-on-non-Unix-systems"><a class="permalink" href="#%23!-and-quoting-on-non-Unix-systems">#</a><a id="and-quoting-on-non-Unix-systems"></a>#! and quoting on non-Unix systems</h2> <p>Unix's #! technique can be simulated on other systems:</p> <dl> <dt id="OS/2"><a class="permalink" href="#OS/2">#</a><a id="OS"></a><a id="OS-2"></a>OS/2</dt> <dd> <p>Put</p> <pre><code class="plaintext">extproc perl -S -your_switches</code></pre> <p>as the first line in <code>*.cmd</code> file (<b>-S</b> due to a bug in cmd.exe's `extproc' handling).</p> </dd> <dt id="MS-DOS"><a class="permalink" href="#MS-DOS">#</a><a id="MS"></a>MS-DOS</dt> <dd> <p>Create a batch file to run your program, and codify it in <code>ALTERNATE_SHEBANG</code> (see the <i>dosish.h</i> file in the source distribution for more information).</p> </dd> <dt id="Win95/NT"><a class="permalink" href="#Win95/NT">#</a><a id="Win95"></a><a id="Win95-NT"></a>Win95/NT</dt> <dd> <p>The Win95/NT installation, when using the ActiveState installer for Perl, will modify the Registry to associate the <i>.pl</i> extension with the perl interpreter. If you install Perl by other means (including building from the sources), you may have to modify the Registry yourself. Note that this means you can no longer tell the difference between an executable Perl program and a Perl library file.</p> </dd> <dt id="Macintosh"><a class="permalink" href="#Macintosh">#</a>Macintosh</dt> <dd> <p>A Macintosh perl program will have the appropriate Creator and Type, so that double-clicking them will invoke the perl application.</p> </dd> <dt id="VMS"><a class="permalink" href="#VMS">#</a>VMS</dt> <dd> <p>Put</p> <pre><code>$ perl -mysw 'f$env("procedure")' 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8' ! $ exit++ + ++$status != 0 and $exit = $status = undef;</code></pre> <p>at the top of your program, where <b>-mysw</b> are any command line switches you want to pass to Perl. You can now invoke the program directly, by saying <code>perl program</code>, or as a DCL procedure, by saying <code>@program</code> (or implicitly via <i>DCL$PATH</i> by just using the name of the program).</p> <p>This incantation is a bit much to remember, but Perl will display it for you if you say <code>perl "-V:startperl"</code>.</p> </dd> </dl> <p>Command-interpreters on non-Unix systems have rather different ideas on quoting than Unix shells. You'll need to learn the special characters in your command-interpreter (<code>*</code>, <code>\</code> and <code>"</code> are common) and how to protect whitespace and these characters to run one-liners (see <b>-e</b> below).</p> <p>On some systems, you may have to change single-quotes to double ones, which you must <i>not</i> do on Unix or Plan 9 systems. You might also have to change a single % to a %%.</p> <p>For example:</p> <pre><code class="plaintext"># Unix perl -e 'print "Hello world\n"' # MS-DOS, etc. perl -e "print \"Hello world\n\"" # Macintosh print "Hello world\n" (then Run "Myscript" or Shift-Command-R) # VMS perl -e "print ""Hello world\n"""</code></pre> <p>The problem is that none of this is reliable: it depends on the command and it is entirely possible neither works. If <b>4DOS</b> were the command shell, this would probably work better:</p> <pre><code class="plaintext">perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""</code></pre> <p><b>CMD.EXE</b> in Windows NT slipped a lot of standard Unix functionality in when nobody was looking, but just try to find documentation for its quoting rules.</p> <p>Under the Macintosh, it depends which environment you are using. The MacPerl shell, or MPW, is much like Unix shells in its support for several quoting variants, except that it makes free use of the Macintosh's non-ASCII characters as control characters.</p> <p>There is no general solution to all of this. It's just a mess.</p> <h2 id="Location-of-Perl"><a class="permalink" href="#Location-of-Perl">#</a><a id="Location"></a>Location of Perl</h2> <p>It may seem obvious to say, but Perl is useful only when users can easily find it. When possible, it's good for both <i>/usr/bin/perl</i> and <i>/usr/local/bin/perl</i> to be symlinks to the actual binary. If that can't be done, system administrators are strongly encouraged to put (symlinks to) perl and its accompanying utilities into a directory typically found along a user's PATH, or in some other obvious and convenient place.</p> <p>In this documentation, <code>#!/usr/bin/perl</code> on the first line of the program will stand in for whatever method works on your system. You are advised to use a specific path if you care about a specific version.</p> <pre><code class="plaintext">#!/usr/local/bin/perl5.00554</code></pre> <p>or if you just want to be running at least version, place a statement like this at the top of your program:</p> <pre><code>use 5.005_54;</code></pre> <h2 id="Command-Switches"><a class="permalink" href="#Command-Switches">#</a><a id="Command"></a>Command Switches</h2> <p>As with all standard commands, a single-character switch may be clustered with the following switch, if any.</p> <pre><code class="plaintext">#!/usr/bin/perl -spi.orig # same as -s -p -i.orig</code></pre> <p>Switches include:</p> <dl> <dt id="-0[octal/hexadecimal]"><a class="permalink" href="#-0%5Boctal/hexadecimal%5D">#</a><a id="octal-hexadecimal"></a><b>-0</b>[<i>octal/hexadecimal</i>]</dt> <dd> <p>specifies the input record separator (<code>$/</code>) as an octal or hexadecimal number. If there are no digits, the null character is the separator. Other switches may precede or follow the digits. For example, if you have a version of <b>find</b> which can print filenames terminated by the null character, you can say this:</p> <pre><code class="plaintext">find . -name '*.orig' -print0 | perl -n0e unlink</code></pre> <p>The special value 00 will cause Perl to slurp files in paragraph mode. The value 0777 will cause Perl to slurp files whole because there is no legal byte with that value.</p> <p>If you want to specify any Unicode character, use the hexadecimal format: <code>-0xHHH...</code>, where the <code>H</code> are valid hexadecimal digits. (This means that you cannot use the <code>-x</code> with a directory name that consists of hexadecimal digits.)</p> </dd> <dt id="-a"><a class="permalink" href="#-a">#</a><a id="a"></a><b>-a</b></dt> <dd> <p>turns on autosplit mode when used with a <b>-n</b> or <b>-p</b>. An implicit split command to the @F array is done as the first thing inside the implicit while loop produced by the <b>-n</b> or <b>-p</b>.</p> <pre><code>perl -ane 'print pop(@F), "\n";'</code></pre> <p>is equivalent to</p> <pre><code> while (<>) { @F = split(' '); print pop(@F), "\n"; }</code></pre> <p>An alternate delimiter may be specified using <b>-F</b>.</p> </dd> <dt id="-C-[number/list]"><a class="permalink" href="#-C-%5Bnumber/list%5D">#</a><a id="C-number-list"></a><b>-C [<i>number/list</i>]</b></dt> <dd> <p>The <code>-C</code> flag controls some Unicode of the Perl Unicode features.</p> <p>As of 5.8.1, the <code>-C</code> can be followed either by a number or a list of option letters. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers.</p> <pre><code>I 1 STDIN is assumed to be in UTF-8 O 2 STDOUT will be in UTF-8 E 4 STDERR will be in UTF-8 S 7 I + O + E i 8 UTF-8 is the default PerlIO layer for input streams o 16 UTF-8 is the default PerlIO layer for output streams D 24 i + o A 32 the @ARGV elements are expected to be strings encoded in UTF-8 L 64 normally the "IOEioA" are unconditional, the L makes them conditional on the locale environment variables (the LC_ALL, LC_TYPE, and LANG, in the order of decreasing precedence) -- if the variables indicate UTF-8, then the selected "IOEioA" are in effect</code></pre> <p>For example, <code>-COE</code> and <code>-C6</code> will both turn on UTF-8-ness on both STDOUT and STDERR. Repeating letters is just redundant, not cumulative nor toggling.</p> <p>The <code>io</code> options mean that any subsequent open() (or similar I/O operations) will have the <code>:utf8</code> PerlIO layer implicitly applied to them, in other words, UTF-8 is expected from any input stream, and UTF-8 is produced to any output stream. This is just the default, with explicit layers in open() and with binmode() one can manipulate streams as usual.</p> <p><code>-C</code> on its own (not followed by any number or option list), or the empty string <code>""</code> for the <code>PERL_UNICODE</code> environment variable, has the same effect as <code>-CSDL</code>. In other words, the standard I/O handles and the default <code>open()</code> layer are UTF-8-fied <b>but</b> only if the locale environment variables indicate a UTF-8 locale. This behaviour follows the <i>implicit</i> (and problematic) UTF-8 behaviour of Perl 5.8.0.</p> <p>You can use <code>-C0</code> (or <code>"0"</code> for <code>PERL_UNICODE</code>) to explicitly disable all the above Unicode features.</p> <p>The read-only magic variable <code>${^UNICODE}</code> reflects the numeric value of this setting. This is variable is set during Perl startup and is thereafter read-only. If you want runtime effects, use the three-arg open() (see <a href="/5.8.4/perlfunc#open">"open" in perlfunc</a>), the two-arg binmode() (see <a href="/5.8.4/perlfunc#binmode">"binmode" in perlfunc</a>), and the <code>open</code> pragma (see <a href="/5.8.4/open">open</a>).</p> <p>(In Perls earlier than 5.8.1 the <code>-C</code> switch was a Win32-only switch that enabled the use of Unicode-aware "wide system call" Win32 APIs. This feature was practically unused, however, and the command line switch was therefore "recycled".)</p> </dd> <dt id="-c"><a class="permalink" href="#-c">#</a><a id="c"></a><b>-c</b></dt> <dd> <p>causes Perl to check the syntax of the program and then exit without executing it. Actually, it <i>will</i> execute <code>BEGIN</code>, <code>CHECK</code>, and <code>use</code> blocks, because these are considered as occurring outside the execution of your program. <code>INIT</code> and <code>END</code> blocks, however, will be skipped.</p> </dd> <dt id="-d"><a class="permalink" href="#-d">#</a><a id="d"></a><b>-d</b></dt> <dd> <p>runs the program under the Perl debugger. See <a href="/5.8.4/perldebug">perldebug</a>.</p> </dd> <dt id="-d:foo[=bar,baz]"><a class="permalink" href="#-d:foo%5B=bar,baz%5D">#</a><a id="d:foo-bar-baz"></a><b>-d:</b><i>foo[=bar,baz]</i></dt> <dd> <p>runs the program under the control of a debugging, profiling, or tracing module installed as Devel::foo. E.g., <b>-d:DProf</b> executes the program using the Devel::DProf profiler. As with the <b>-M</b> flag, options may be passed to the Devel::foo package where they will be received and interpreted by the Devel::foo::import routine. The comma-separated list of options must follow a <code>=</code> character. See <a href="/5.8.4/perldebug">perldebug</a>.</p> </dd> <dt id="-Dletters"><a class="permalink" href="#-Dletters">#</a><a id="Dletters"></a><b>-D</b><i>letters</i></dt> <dd> </dd> <dt id="-Dnumber"><a class="permalink" href="#-Dnumber">#</a><a id="Dnumber"></a><b>-D</b><i>number</i></dt> <dd> <p>sets debugging flags. To watch how it executes your program, use <b>-Dtls</b>. (This works only if debugging is compiled into your Perl.) Another nice value is <b>-Dx</b>, which lists your compiled syntax tree. And <b>-Dr</b> displays compiled regular expressions; the format of the output is explained in <a href="/5.8.4/perldebguts">perldebguts</a>.</p> <p>As an alternative, specify a number instead of list of letters (e.g., <b>-D14</b> is equivalent to <b>-Dtls</b>):</p> <pre><code class="plaintext"> 1 p Tokenizing and parsing 2 s Stack snapshots with v, displays all stacks 4 l Context (loop) stack processing 8 t Trace execution 16 o Method and overloading resolution 32 c String/numeric conversions 64 P Print profiling info, preprocessor command for -P, source file input state 128 m Memory allocation 256 f Format processing 512 r Regular expression parsing and execution 1024 x Syntax tree dump 2048 u Tainting checks 4096 (Obsolete, previously used for LEAKTEST) 8192 H Hash dump -- usurps values() 16384 X Scratchpad allocation 32768 D Cleaning up 65536 S Thread synchronization 131072 T Tokenising 262144 R Include reference counts of dumped variables (eg when using -Ds) 524288 J Do not s,t,P-debug (Jump over) opcodes within package DB 1048576 v Verbose: use in conjunction with other flags 2097152 C Copy On Write</code></pre> <p>All these flags require <b>-DDEBUGGING</b> when you compile the Perl executable (but see <a href="/5.8.4/Devel::Peek">Devel::Peek</a>, <a href="/5.8.4/re">re</a> which may change this). See the <i>INSTALL</i> file in the Perl source distribution for how to do this. This flag is automatically set if you include <b>-g</b> option when <code>Configure</code> asks you about optimizer/debugger flags.</p> <p>If you're just trying to get a print out of each line of Perl code as it executes, the way that <code>sh -x</code> provides for shell scripts, you can't use Perl's <b>-D</b> switch. Instead do this</p> <pre><code class="plaintext"># If you have "env" utility env=PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program # Bourne shell syntax $ PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=2" perl -dS program # csh syntax % (setenv PERLDB_OPTS "NonStop=1 AutoTrace=1 frame=2"; perl -dS program)</code></pre> <p>See <a href="/5.8.4/perldebug">perldebug</a> for details and variations.</p> </dd> <dt id="-e-commandline"><a class="permalink" href="#-e-commandline">#</a><a id="e-commandline"></a><b>-e</b> <i>commandline</i></dt> <dd> <p>may be used to enter one line of program. If <b>-e</b> is given, Perl will not look for a filename in the argument list. Multiple <b>-e</b> commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.</p> </dd> <dt id="-Fpattern"><a class="permalink" href="#-Fpattern">#</a><a id="Fpattern"></a><b>-F</b><i>pattern</i></dt> <dd> <p>specifies the pattern to split on if <b>-a</b> is also in effect. The pattern may be surrounded by <code>//</code>, <code>""</code>, or <code>''</code>, otherwise it will be put in single quotes.</p> </dd> <dt id="-h"><a class="permalink" href="#-h">#</a><a id="h"></a><b>-h</b></dt> <dd> <p>prints a summary of the options.</p> </dd> <dt id="-i[extension]"><a class="permalink" href="#-i%5Bextension%5D">#</a><a id="i-extension"></a><b>-i</b>[<i>extension</i>]</dt> <dd> <p>specifies that files processed by the <code><></code> construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements. The extension, if supplied, is used to modify the name of the old file to make a backup copy, following these rules:</p> <p>If no extension is supplied, no backup is made and the current file is overwritten.</p> <p>If the extension doesn't contain a <code>*</code>, then it is appended to the end of the current filename as a suffix. If the extension does contain one or more <code>*</code> characters, then each <code>*</code> is replaced with the current filename. In Perl terms, you could think of this as:</p> <pre><code>($backup = $extension) =~ s/\*/$file_name/g;</code></pre> <p>This allows you to add a prefix to the backup file, instead of (or in addition to) a suffix:</p> <pre><code class="plaintext">$ perl -pi'orig_*' -e 's/bar/baz/' fileA # backup to 'orig_fileA'</code></pre> <p>Or even to place backup copies of the original files into another directory (provided the directory already exists):</p> <pre><code class="plaintext">$ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'</code></pre> <p>These sets of one-liners are equivalent:</p> <pre><code class="plaintext">$ perl -pi -e 's/bar/baz/' fileA # overwrite current file $ perl -pi'*' -e 's/bar/baz/' fileA # overwrite current file $ perl -pi'.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig' $ perl -pi'*.orig' -e 's/bar/baz/' fileA # backup to 'fileA.orig'</code></pre> <p>From the shell, saying</p> <pre><code class="plaintext">$ perl -p -i.orig -e "s/foo/bar/; ... "</code></pre> <p>is the same as using the program:</p> <pre><code>#!/usr/bin/perl -pi.orig s/foo/bar/;</code></pre> <p>which is equivalent to</p> <pre><code> #!/usr/bin/perl $extension = '.orig'; LINE: while (<>) { if ($ARGV ne $oldargv) { if ($extension !~ /\*/) { $backup = $ARGV . $extension; } else { ($backup = $extension) =~ s/\*/$ARGV/g; } rename($ARGV, $backup); open(ARGVOUT, ">$ARGV"); select(ARGVOUT); $oldargv = $ARGV; } s/foo/bar/; } continue { print; # this prints to original filename } select(STDOUT);</code></pre> <p>except that the <b>-i</b> form doesn't need to compare $ARGV to $oldargv to know when the filename has changed. It does, however, use ARGVOUT for the selected filehandle. Note that STDOUT is restored as the default output filehandle after the loop.</p> <p>As shown above, Perl creates the backup file whether or not any output is actually changed. So this is just a fancy way to copy files:</p> <pre><code class="plaintext">$ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3... or $ perl -p -i'.orig' -e 1 file1 file2 file3...</code></pre> <p>You can use <code>eof</code> without parentheses to locate the end of each input file, in case you want to append to each file, or reset line numbering (see example in <a href="/5.8.4/perlfunc#eof">"eof" in perlfunc</a>).</p> <p>If, for a given file, Perl is unable to create the backup file as specified in the extension then it will skip that file and continue on with the next one (if it exists).</p> <p>For a discussion of issues surrounding file permissions and <b>-i</b>, see <a href="/5.8.4/perlfaq5#Why-does-Perl-let-me-delete-read-only-files%3F-Why-does-i-clobber-protected-files%3F-Isn%27t-this-a-bug-in-Perl%3F">"Why does Perl let me delete read-only files? Why does -i clobber protected files? Isn't this a bug in Perl?" in perlfaq5</a>.</p> <p>You cannot use <b>-i</b> to create directories or to strip extensions from files.</p> <p>Perl does not expand <code>~</code> in filenames, which is good, since some folks use it for their backup files:</p> <pre><code class="plaintext">$ perl -pi~ -e 's/foo/bar/' file1 file2 file3...</code></pre> <p>Finally, the <b>-i</b> switch does not impede execution when no files are given on the command line. In this case, no backup is made (the original file cannot, of course, be determined) and processing proceeds from STDIN to STDOUT as might be expected.</p> </dd> <dt id="-Idirectory"><a class="permalink" href="#-Idirectory">#</a><a id="Idirectory"></a><b>-I</b><i>directory</i></dt> <dd> <p>Directories specified by <b>-I</b> are prepended to the search path for modules (<code>@INC</code>), and also tells the C preprocessor where to search for include files. The C preprocessor is invoked with <b>-P</b>; by default it searches /usr/include and /usr/lib/perl.</p> </dd> <dt id="-l[octnum]"><a class="permalink" href="#-l%5Boctnum%5D">#</a><a id="l-octnum"></a><b>-l</b>[<i>octnum</i>]</dt> <dd> <p>enables automatic line-ending processing. It has two separate effects. First, it automatically chomps <code>$/</code> (the input record separator) when used with <b>-n</b> or <b>-p</b>. Second, it assigns <code>$\</code> (the output record separator) to have the value of <i>octnum</i> so that any print statements will have that separator added back on. If <i>octnum</i> is omitted, sets <code>$\</code> to the current value of <code>$/</code>. For instance, to trim lines to 80 columns:</p> <pre><code>perl -lpe 'substr($_, 80) = ""'</code></pre> <p>Note that the assignment <code>$\ = $/</code> is done when the switch is processed, so the input record separator can be different than the output record separator if the <b>-l</b> switch is followed by a <b>-0</b> switch:</p> <pre><code>gnufind / -print0 | perl -ln0e 'print "found $_" if -p'</code></pre> <p>This sets <code>$\</code> to newline and then sets <code>$/</code> to the null character.</p> </dd> <dt id="-m[-]module"><a class="permalink" href="#-m%5B-%5Dmodule">#</a><a id="m---module"></a><b>-m</b>[<b>-</b>]<i>module</i></dt> <dd> </dd> <dt id="-M[-]module"><a class="permalink" href="#-M%5B-%5Dmodule">#</a><a id="M---module"></a><b>-M</b>[<b>-</b>]<i>module</i></dt> <dd> </dd> <dt id="-M[-]'module-...'"><a class="permalink" href="#-M%5B-%5D'module-...'">#</a><a id="M---module1"></a><b>-M</b>[<b>-</b>]<i>'module ...'</i></dt> <dd> </dd> <dt id="-[mM][-]module=arg[,arg]..."><a class="permalink" href="#-%5BmM%5D%5B-%5Dmodule=arg%5B,arg%5D...">#</a><a id="mM---module-arg-arg"></a><b>-[mM]</b>[<b>-</b>]<i>module=arg[,arg]...</i></dt> <dd> <p><b>-m</b><i>module</i> executes <code>use</code> <i>module</i> <code>();</code> before executing your program.</p> <p><b>-M</b><i>module</i> executes <code>use</code> <i>module</i> <code>;</code> before executing your program. You can use quotes to add extra code after the module name, e.g., <code>'-Mmodule qw(foo bar)'</code>.</p> <p>If the first character after the <b>-M</b> or <b>-m</b> is a dash (<code>-</code>) then the 'use' is replaced with 'no'.</p> <p>A little builtin syntactic sugar means you can also say <b>-mmodule=foo,bar</b> or <b>-Mmodule=foo,bar</b> as a shortcut for <code>'-Mmodule qw(foo bar)'</code>. This avoids the need to use quotes when importing symbols. The actual code generated by <b>-Mmodule=foo,bar</b> is <code>use module split(/,/,q{foo,bar})</code>. Note that the <code>=</code> form removes the distinction between <b>-m</b> and <b>-M</b>.</p> </dd> <dt id="-n"><a class="permalink" href="#-n">#</a><a id="n"></a><b>-n</b></dt> <dd> <p>causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like <b>sed -n</b> or <b>awk</b>:</p> <pre><code> LINE: while (<>) { ... # your program goes here }</code></pre> <p>Note that the lines are not printed by default. See <b>-p</b> to have lines printed. If a file named by an argument cannot be opened for some reason, Perl warns you about it and moves on to the next file.</p> <p>Here is an efficient way to delete all files that haven't been modifed for at least a week:</p> <pre><code class="plaintext">find . -mtime +7 -print | perl -nle unlink</code></pre> <p>This is faster than using the <b>-exec</b> switch of <b>find</b> because you don't have to start a process on every filename found. It does suffer from the bug of mishandling newlines in pathnames, which you can fix if you follow the example under <b>-0</b>.</p> <p><code>BEGIN</code> and <code>END</code> blocks may be used to capture control before or after the implicit program loop, just as in <b>awk</b>.</p> </dd> <dt id="-p"><a class="permalink" href="#-p">#</a><a id="p"></a><b>-p</b></dt> <dd> <p>causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like <b>sed</b>:</p> <pre><code> LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }</code></pre> <p>If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves on to the next file. Note that the lines are printed automatically. An error occurring during printing is treated as fatal. To suppress printing use the <b>-n</b> switch. A <b>-p</b> overrides a <b>-n</b> switch.</p> <p><code>BEGIN</code> and <code>END</code> blocks may be used to capture control before or after the implicit loop, just as in <b>awk</b>.</p> </dd> <dt id="-P"><a class="permalink" href="#-P">#</a><a id="P"></a><b>-P</b></dt> <dd> <p><b>NOTE: Use of -P is strongly discouraged because of its inherent problems, including poor portability.</b></p> <p>This option causes your program to be run through the C preprocessor before compilation by Perl. Because both comments and <b>cpp</b> directives begin with the # character, you should avoid starting comments with any words recognized by the C preprocessor such as <code>"if"</code>, <code>"else"</code>, or <code>"define"</code>.</p> <p>If you're considering using <code>-P</code>, you might also want to look at the Filter::cpp module from CPAN.</p> <p>The problems of -P include, but are not limited to:</p> <ul> <li><p>The <code>#!</code> line is stripped, so any switches there don't apply.</p> </li> <li><p>A <code>-P</code> on a <code>#!</code> line doesn't work.</p> </li> <li><p><b>All</b> lines that begin with (whitespace and) a <code>#</code> but do not look like cpp commands, are stripped, including anything inside Perl strings, regular expressions, and here-docs .</p> </li> <li><p>In some platforms the C preprocessor knows too much: it knows about the C++ -style until-end-of-line comments starting with <code>"//"</code>. This will cause problems with common Perl constructs like</p> <pre><code>s/foo//;</code></pre> <p>because after -P this will became illegal code</p> <pre><code class="plaintext">s/foo</code></pre> <p>The workaround is to use some other quoting separator than <code>"/"</code>, like for example <code>"!"</code>:</p> <pre><code>s!foo!!;</code></pre> </li> <li><p>It requires not only a working C preprocessor but also a working <i>sed</i>. If not on UNIX, you are probably out of luck on this.</p> </li> <li><p>Script line numbers are not preserved.</p> </li> <li><p>The <code>-x</code> does not work with <code>-P</code>.</p> </li> </ul> </dd> <dt id="-s"><a class="permalink" href="#-s">#</a><a id="s"></a><b>-s</b></dt> <dd> <p>enables rudimentary switch parsing for switches on the command line after the program name but before any filename arguments (or before an argument of <b>--</b>). This means you can have switches with two leading dashes (<b>--help</b>). Any switch found there is removed from @ARGV and sets the corresponding variable in the Perl program. The following program prints "1" if the program is invoked with a <b>-xyz</b> switch, and "abc" if it is invoked with <b>-xyz=abc</b>.</p> <pre><code>#!/usr/bin/perl -s if ($xyz) { print "$xyz\n" }</code></pre> <p>Do note that <b>--help</b> creates the variable ${-help}, which is not compliant with <code>strict refs</code>.</p> </dd> <dt id="-S"><a class="permalink" href="#-S">#</a><a id="S"></a><b>-S</b></dt> <dd> <p>makes Perl use the PATH environment variable to search for the program (unless the name of the program contains directory separators).</p> <p>On some platforms, this also makes Perl append suffixes to the filename while searching for it. For example, on Win32 platforms, the ".bat" and ".cmd" suffixes are appended if a lookup for the original name fails, and if the name does not already end in one of those suffixes. If your Perl was compiled with DEBUGGING turned on, using the -Dp switch to Perl shows how the search progresses.</p> <p>Typically this is used to emulate #! startup on platforms that don't support #!. This example works on many platforms that have a shell compatible with Bourne shell:</p> <pre><code> #!/usr/bin/perl eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}' if $running_under_some_shell;</code></pre> <p>The system ignores the first line and feeds the program to <i>/bin/sh</i>, which proceeds to try to execute the Perl program as a shell script. The shell executes the second line as a normal shell command, and thus starts up the Perl interpreter. On some systems $0 doesn't always contain the full pathname, so the <b>-S</b> tells Perl to search for the program if necessary. After Perl locates the program, it parses the lines and ignores them because the variable $running_under_some_shell is never true. If the program will be interpreted by csh, you will need to replace <code>${1+"$@"}</code> with <code>$*</code>, even though that doesn't understand embedded spaces (and such) in the argument list. To start up sh rather than csh, some systems may have to replace the #! line with a line containing just a colon, which will be politely ignored by Perl. Other systems can't control that, and need a totally devious construct that will work under any of <b>csh</b>, <b>sh</b>, or Perl, such as the following:</p> <pre><code>eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -wS $0 $argv:q' if $running_under_some_shell;</code></pre> <p>If the filename supplied contains directory separators (i.e., is an absolute or relative pathname), and if that file is not found, platforms that append file extensions will do so and try to look for the file with those extensions added, one by one.</p> <p>On DOS-like platforms, if the program does not contain directory separators, it will first be searched for in the current directory before being searched for on the PATH. On Unix platforms, the program will be searched for strictly on the PATH.</p> </dd> <dt id="-t"><a class="permalink" href="#-t">#</a><a id="t"></a><b>-t</b></dt> <dd> <p>Like <b>-T</b>, but taint checks will issue warnings rather than fatal errors. These warnings can be controlled normally with <code>no warnings qw(taint)</code>.</p> <p><b>NOTE: this is not a substitute for -T.</b> This is meant only to be used as a temporary development aid while securing legacy code: for real production code and for new secure code written from scratch always use the real <b>-T</b>.</p> </dd> <dt id="-T"><a class="permalink" href="#-T">#</a><a id="T"></a><b>-T</b></dt> <dd> <p>forces "taint" checks to be turned on so you can test them. Ordinarily these checks are done only when running setuid or setgid. It's a good idea to turn them on explicitly for programs that run on behalf of someone else whom you might not necessarily trust, such as CGI programs or any internet servers you might write in Perl. See <a href="/5.8.4/perlsec">perlsec</a> for details. For security reasons, this option must be seen by Perl quite early; usually this means it must appear early on the command line or in the #! line for systems which support that construct.</p> </dd> <dt id="-u"><a class="permalink" href="#-u">#</a><a id="u"></a><b>-u</b></dt> <dd> <p>This obsolete switch causes Perl to dump core after compiling your program. You can then in theory take this core dump and turn it into an executable file by using the <b>undump</b> program (not supplied). This speeds startup at the expense of some disk space (which you can minimize by stripping the executable). (Still, a "hello world" executable comes out to about 200K on my machine.) If you want to execute a portion of your program before dumping, use the dump() operator instead. Note: availability of <b>undump</b> is platform specific and may not be available for a specific port of Perl.</p> <p>This switch has been superseded in favor of the new Perl code generator backends to the compiler. See <a href="/5.8.4/B">B</a> and <a href="/5.8.4/B::Bytecode">B::Bytecode</a> for details.</p> </dd> <dt id="-U"><a class="permalink" href="#-U">#</a><a id="U"></a><b>-U</b></dt> <dd> <p>allows Perl to do unsafe operations. Currently the only "unsafe" operations are the unlinking of directories while running as superuser, and running setuid programs with fatal taint checks turned into warnings. Note that the <b>-w</b> switch (or the <code>$^W</code> variable) must be used along with this option to actually <i>generate</i> the taint-check warnings.</p> </dd> <dt id="-v"><a class="permalink" href="#-v">#</a><a id="v"></a><b>-v</b></dt> <dd> <p>prints the version and patchlevel of your perl executable.</p> </dd> <dt id="-V"><a class="permalink" href="#-V">#</a><a id="V"></a><b>-V</b></dt> <dd> <p>prints summary of the major perl configuration values and the current values of @INC.</p> </dd> <dt id="-V:name"><a class="permalink" href="#-V:name">#</a><a id="V:name"></a><b>-V:</b><i>name</i></dt> <dd> <p>Prints to STDOUT the value of the named configuration variable. For example,</p> <pre><code class="plaintext">$ perl -V:man.dir</code></pre> <p>will provide strong clues about what your MANPATH variable should be set to in order to access the Perl documentation.</p> </dd> <dt id="-w"><a class="permalink" href="#-w">#</a><a id="w"></a><b>-w</b></dt> <dd> <p>prints warnings about dubious constructs, such as variable names that are mentioned only once and scalar variables that are used before being set, redefined subroutines, references to undefined filehandles or filehandles opened read-only that you are attempting to write on, values used as a number that doesn't look like numbers, using an array as though it were a scalar, if your subroutines recurse more than 100 deep, and innumerable other things.</p> <p>This switch really just enables the internal <code>$^W</code> variable. You can disable or promote into fatal errors specific warnings using <code>__WARN__</code> hooks, as described in <a href="/5.8.4/perlvar">perlvar</a> and <a href="/5.8.4/perlfunc#warn">"warn" in perlfunc</a>. See also <a href="/5.8.4/perldiag">perldiag</a> and <a href="/5.8.4/perltrap">perltrap</a>. A new, fine-grained warning facility is also available if you want to manipulate entire classes of warnings; see <a href="/5.8.4/warnings">warnings</a> or <a href="/5.8.4/perllexwarn">perllexwarn</a>.</p> </dd> <dt id="-W"><a class="permalink" href="#-W">#</a><a id="W"></a><b>-W</b></dt> <dd> <p>Enables all warnings regardless of <code>no warnings</code> or <code>$^W</code>. See <a href="/5.8.4/perllexwarn">perllexwarn</a>.</p> </dd> <dt id="-X"><a class="permalink" href="#-X">#</a><a id="X"></a><b>-X</b></dt> <dd> <p>Disables all warnings regardless of <code>use warnings</code> or <code>$^W</code>. See <a href="/5.8.4/perllexwarn">perllexwarn</a>.</p> </dd> <dt id="-x-directory"><a class="permalink" href="#-x-directory">#</a><a id="x-directory"></a><b>-x</b> <i>directory</i></dt> <dd> <p>tells Perl that the program is embedded in a larger chunk of unrelated ASCII text, such as in a mail message. Leading garbage will be discarded until the first line that starts with #! and contains the string "perl". Any meaningful switches on that line will be applied. If a directory name is specified, Perl will switch to that directory before running the program. The <b>-x</b> switch controls only the disposal of leading garbage. The program must be terminated with <code>__END__</code> if there is trailing garbage to be ignored (the program can process any or all of the trailing garbage via the DATA filehandle if desired).</p> </dd> </dl> <h1 id="ENVIRONMENT"><a class="permalink" href="#ENVIRONMENT">#</a>ENVIRONMENT</h1> <dl> <dt id="HOME"><a class="permalink" href="#HOME">#</a>HOME</dt> <dd> <p>Used if chdir has no argument.</p> </dd> <dt id="LOGDIR"><a class="permalink" href="#LOGDIR">#</a>LOGDIR</dt> <dd> <p>Used if chdir has no argument and HOME is not set.</p> </dd> <dt id="PATH"><a class="permalink" href="#PATH">#</a>PATH</dt> <dd> <p>Used in executing subprocesses, and in finding the program if <b>-S</b> is used.</p> </dd> <dt id="PERL5LIB"><a class="permalink" href="#PERL5LIB">#</a>PERL5LIB</dt> <dd> <p>A list of directories in which to look for Perl library files before looking in the standard library and the current directory. Any architecture-specific directories under the specified locations are automatically included if they exist. If PERL5LIB is not defined, PERLLIB is used. Directories are separated (like in PATH) by a colon on unixish platforms and by a semicolon on Windows (the proper path separator being given by the command <code>perl -V:path_sep</code>).</p> <p>When running taint checks (either because the program was running setuid or setgid, or the <b>-T</b> switch was used), neither variable is used. The program should instead say:</p> <pre><code>use lib "/my/directory";</code></pre> </dd> <dt id="PERL5OPT"><a class="permalink" href="#PERL5OPT">#</a>PERL5OPT</dt> <dd> <p>Command-line options (switches). Switches in this variable are taken as if they were on every Perl command line. Only the <b>-[DIMUdmtw]</b> switches are allowed. When running taint checks (because the program was running setuid or setgid, or the <b>-T</b> switch was used), this variable is ignored. If PERL5OPT begins with <b>-T</b>, tainting will be enabled, and any subsequent options ignored.</p> </dd> <dt id="PERLIO"><a class="permalink" href="#PERLIO">#</a>PERLIO</dt> <dd> <p>A space (or colon) separated list of PerlIO layers. If perl is built to use PerlIO system for IO (the default) these layers effect perl's IO.</p> <p>It is conventional to start layer names with a colon e.g. <code>:perlio</code> to emphasise their similarity to variable "attributes". But the code that parses layer specification strings (which is also used to decode the PERLIO environment variable) treats the colon as a separator.</p> <p>An unset or empty PERLIO is equivalent to <code>:stdio</code>.</p> <p>The list becomes the default for <i>all</i> perl's IO. Consequently only built-in layers can appear in this list, as external layers (such as :encoding()) need IO in order to load them!. See <a href="/5.8.4/open">"open pragma"</a> for how to add external encodings as defaults.</p> <p>The layers that it makes sense to include in the PERLIO environment variable are briefly summarised below. For more details see <a href="/5.8.4/PerlIO">PerlIO</a>.</p> <dl> <dt id=":bytes"><a class="permalink" href="#:bytes">#</a><a id="bytes"></a>:bytes</dt> <dd> <p>A pseudolayer that turns <i>off</i> the <code>:utf8</code> flag for the layer below. Unlikely to be useful on its own in the global PERLIO environment variable. You perhaps were thinking of <code>:crlf:bytes</code> or <code>:perlio:bytes</code>.</p> </dd> <dt id=":crlf"><a class="permalink" href="#:crlf">#</a><a id="crlf"></a>:crlf</dt> <dd> <p>A layer which does CRLF to "\n" translation distinguishing "text" and "binary" files in the manner of MS-DOS and similar operating systems. (It currently does <i>not</i> mimic MS-DOS as far as treating of Control-Z as being an end-of-file marker.)</p> </dd> <dt id=":mmap"><a class="permalink" href="#:mmap">#</a><a id="mmap"></a>:mmap</dt> <dd> <p>A layer which implements "reading" of files by using <code>mmap()</code> to make (whole) file appear in the process's address space, and then using that as PerlIO's "buffer".</p> </dd> <dt id=":perlio"><a class="permalink" href="#:perlio">#</a><a id="perlio"></a>:perlio</dt> <dd> <p>This is a re-implementation of "stdio-like" buffering written as a PerlIO "layer". As such it will call whatever layer is below it for its operations (typically <code>:unix</code>).</p> </dd> <dt id=":pop"><a class="permalink" href="#:pop">#</a><a id="pop"></a>:pop</dt> <dd> <p>An experimental pseudolayer that removes the topmost layer. Use with the same care as is reserved for nitroglycerin.</p> </dd> <dt id=":raw"><a class="permalink" href="#:raw">#</a><a id="raw"></a>:raw</dt> <dd> <p>A pseudolayer that manipulates other layers. Applying the <:raw> layer is equivalent to calling <code>binmode($fh)</code>. It makes the stream pass each byte as-is without any translation. In particular CRLF translation, and/or :utf8 intuited from locale are disabled.</p> <p>Unlike in the earlier versions of Perl <code>:raw</code> is <i>not</i> just the inverse of <code>:crlf</code> - other layers which would affect the binary nature of the stream are also removed or disabled.</p> </dd> <dt id=":stdio"><a class="permalink" href="#:stdio">#</a><a id="stdio"></a>:stdio</dt> <dd> <p>This layer provides PerlIO interface by wrapping system's ANSI C "stdio" library calls. The layer provides both buffering and IO. Note that <code>:stdio</code> layer does <i>not</i> do CRLF translation even if that is platforms normal behaviour. You will need a <code>:crlf</code> layer above it to do that.</p> </dd> <dt id=":unix"><a class="permalink" href="#:unix">#</a><a id="unix"></a>:unix</dt> <dd> <p>Low level layer which calls <code>read</code>, <code>write</code> and <code>lseek</code> etc.</p> </dd> <dt id=":utf8"><a class="permalink" href="#:utf8">#</a><a id="utf8"></a>:utf8</dt> <dd> <p>A pseudolayer that turns on a flag on the layer below to tell perl that output should be in utf8 and that input should be regarded as already in utf8 form. May be useful in PERLIO environment variable to make UTF-8 the default. (To turn off that behaviour use <code>:bytes</code> layer.)</p> </dd> <dt id=":win32"><a class="permalink" href="#:win32">#</a><a id="win32"></a>:win32</dt> <dd> <p>On Win32 platforms this <i>experimental</i> layer uses native "handle" IO rather than unix-like numeric file descriptor layer. Known to be buggy in this release.</p> </dd> </dl> <p>On all platforms the default set of layers should give acceptable results.</p> <p>For UNIX platforms that will equivalent of "unix perlio" or "stdio". Configure is setup to prefer "stdio" implementation if system's library provides for fast access to the buffer, otherwise it uses the "unix perlio" implementation.</p> <p>On Win32 the default in this release is "unix crlf". Win32's "stdio" has a number of bugs/mis-features for perl IO which are somewhat C compiler vendor/version dependent. Using our own <code>crlf</code> layer as the buffer avoids those issues and makes things more uniform. The <code>crlf</code> layer provides CRLF to/from "\n" conversion as well as buffering.</p> <p>This release uses <code>unix</code> as the bottom layer on Win32 and so still uses C compiler's numeric file descriptor routines. There is an experimental native <code>win32</code> layer which is expected to be enhanced and should eventually be the default under Win32.</p> </dd> <dt id="PERLIO_DEBUG"><a class="permalink" href="#PERLIO_DEBUG">#</a>PERLIO_DEBUG</dt> <dd> <p>If set to the name of a file or device then certain operations of PerlIO sub-system will be logged to that file (opened as append). Typical uses are UNIX:</p> <pre><code class="plaintext">PERLIO_DEBUG=/dev/tty perl script ...</code></pre> <p>and Win32 approximate equivalent:</p> <pre><code class="plaintext">set PERLIO_DEBUG=CON perl script ...</code></pre> </dd> <dt id="PERLLIB"><a class="permalink" href="#PERLLIB">#</a>PERLLIB</dt> <dd> <p>A list of directories in which to look for Perl library files before looking in the standard library and the current directory. If PERL5LIB is defined, PERLLIB is not used.</p> </dd> <dt id="PERL5DB"><a class="permalink" href="#PERL5DB">#</a>PERL5DB</dt> <dd> <p>The command used to load the debugger code. The default is:</p> <pre><code class="plaintext">BEGIN { require 'perl5db.pl' }</code></pre> </dd> <dt id="PERL5SHELL-(specific-to-the-Win32-port)"><a class="permalink" href="#PERL5SHELL-(specific-to-the-Win32-port)">#</a><a id="PERL5SHELL"></a><a id="PERL5SHELL-specific-to-the-Win32-port"></a>PERL5SHELL (specific to the Win32 port)</dt> <dd> <p>May be set to an alternative shell that perl must use internally for executing "backtick" commands or system(). Default is <code>cmd.exe /x/d/c</code> on WindowsNT and <code>command.com /c</code> on Windows95. The value is considered to be space-separated. Precede any character that needs to be protected (like a space or backslash) with a backslash.</p> <p>Note that Perl doesn't use COMSPEC for this purpose because COMSPEC has a high degree of variability among users, leading to portability concerns. Besides, perl can use a shell that may not be fit for interactive use, and setting COMSPEC to such a shell may interfere with the proper functioning of other programs (which usually look in COMSPEC to find a shell fit for interactive use).</p> </dd> <dt id="PERL_DEBUG_MSTATS"><a class="permalink" href="#PERL_DEBUG_MSTATS">#</a>PERL_DEBUG_MSTATS</dt> <dd> <p>Relevant only if perl is compiled with the malloc included with the perl distribution (that is, if <code>perl -V:d_mymalloc</code> is 'define'). If set, this causes memory statistics to be dumped after execution. If set to an integer greater than one, also causes memory statistics to be dumped after compilation.</p> </dd> <dt id="PERL_DESTRUCT_LEVEL"><a class="permalink" href="#PERL_DESTRUCT_LEVEL">#</a>PERL_DESTRUCT_LEVEL</dt> <dd> <p>Relevant only if your perl executable was built with <b>-DDEBUGGING</b>, this controls the behavior of global destruction of objects and other references. See <a href="/5.8.4/perlhack#PERL_DESTRUCT_LEVEL">"PERL_DESTRUCT_LEVEL" in perlhack</a> for more information.</p> </dd> <dt id="PERL_DL_NONLAZY"><a class="permalink" href="#PERL_DL_NONLAZY">#</a>PERL_DL_NONLAZY</dt> <dd> <p>Set to one to have perl resolve <b>all</b> undefined symbols when it loads a dynamic library. The default behaviour is to resolve symbols when they are used. Setting this variable is useful during testing of extensions as it ensures that you get an error on misspelled function names even if the test suite doesn't call it.</p> </dd> <dt id="PERL_ENCODING"><a class="permalink" href="#PERL_ENCODING">#</a>PERL_ENCODING</dt> <dd> <p>If using the <code>encoding</code> pragma without an explicit encoding name, the PERL_ENCODING environment variable is consulted for an encoding name.</p> </dd> <dt id="PERL_HASH_SEED"><a class="permalink" href="#PERL_HASH_SEED">#</a>PERL_HASH_SEED</dt> <dd> <p>(Since Perl 5.8.1.) Used to randomise Perl's internal hash function. To emulate the pre-5.8.1 behaviour, set to an integer (zero means exactly the same order as 5.8.0). "Pre-5.8.1" means, among other things, that hash keys will be ordered the same between different runs of Perl.</p> <p>The default behaviour is to randomise unless the PERL_HASH_SEED is set. If Perl has been compiled with <code>-DUSE_HASH_SEED_EXPLICIT</code>, the default behaviour is <b>not</b> to randomise unless the PERL_HASH_SEED is set.</p> <p>If PERL_HASH_SEED is unset or set to a non-numeric string, Perl uses the pseudorandom seed supplied by the operating system and libraries. This means that each different run of Perl will have a different ordering of the results of keys(), values(), and each().</p> <p><b>Please note that the hash seed is sensitive information</b>. Hashes are randomized to protect against local and remote attacks against Perl code. By manually setting a seed this protection may be partially or completely lost.</p> <p>See <a href="/5.8.4/perlsec#Algorithmic-Complexity-Attacks">"Algorithmic Complexity Attacks" in perlsec</a> and <a href="#PERL_HASH_SEED_DEBUG">"PERL_HASH_SEED_DEBUG"</a> for more information.</p> </dd> <dt id="PERL_HASH_SEED_DEBUG"><a class="permalink" href="#PERL_HASH_SEED_DEBUG">#</a>PERL_HASH_SEED_DEBUG</dt> <dd> <p>(Since Perl 5.8.1.) Set to one to display (to STDERR) the value of the hash seed at the beginning of execution. This, combined with <a href="#PERL_HASH_SEED">"PERL_HASH_SEED"</a> is intended to aid in debugging nondeterministic behavior caused by hash randomization.</p> <p><b>Note that the hash seed is sensitive information</b>: by knowing it one can craft a denial-of-service attack against Perl code, even remotely, see <a href="/5.8.4/perlsec#Algorithmic-Complexity-Attacks">"Algorithmic Complexity Attacks" in perlsec</a> for more information. <b>Do not disclose the hash seed</b> to people who don't need to know it. See also hash_seed() of <a href="/5.8.4/Hash::Util">Hash::Util</a>.</p> </dd> <dt id="PERL_ROOT-(specific-to-the-VMS-port)"><a class="permalink" href="#PERL_ROOT-(specific-to-the-VMS-port)">#</a><a id="PERL_ROOT"></a><a id="PERL_ROOT-specific-to-the-VMS-port"></a>PERL_ROOT (specific to the VMS port)</dt> <dd> <p>A translation concealed rooted logical name that contains perl and the logical device for the @INC path on VMS only. Other logical names that affect perl on VMS include PERLSHR, PERL_ENV_TABLES, and SYS$TIMEZONE_DIFFERENTIAL but are optional and discussed further in <a href="/5.8.4/perlvms">perlvms</a> and in <i>README.vms</i> in the Perl source distribution.</p> </dd> <dt id="PERL_SIGNALS"><a class="permalink" href="#PERL_SIGNALS">#</a>PERL_SIGNALS</dt> <dd> <p>In Perls 5.8.1 and later. If set to <code>unsafe</code> the pre-Perl-5.8.0 signals behaviour (immediate but unsafe) is restored. If set to <code>safe</code> the safe (or deferred) signals are used. See <a href="/5.8.4/perlipc#Deferred-Signals-(Safe-signals)">"Deferred Signals (Safe signals)" in perlipc</a>.</p> </dd> <dt id="PERL_UNICODE"><a class="permalink" href="#PERL_UNICODE">#</a>PERL_UNICODE</dt> <dd> <p>Equivalent to the <b>-C</b> command-line switch. Note that this is not a boolean variable-- setting this to <code>"1"</code> is not the right way to "enable Unicode" (whatever that would mean). You can use <code>"0"</code> to "disable Unicode", though (or alternatively unset PERL_UNICODE in your shell before starting Perl). See the description of the <code>-C</code> switch for more information.</p> </dd> <dt id="SYS$LOGIN-(specific-to-the-VMS-port)"><a class="permalink" href="#SYS$LOGIN-(specific-to-the-VMS-port)">#</a><a id="SYS"></a><a id="SYS-LOGIN-specific-to-the-VMS-port"></a>SYS$LOGIN (specific to the VMS port)</dt> <dd> <p>Used if chdir has no argument and HOME and LOGDIR are not set.</p> </dd> </dl> <p>Perl also has environment variables that control how Perl handles data specific to particular natural languages. See <a href="/5.8.4/perllocale">perllocale</a>.</p> <p>Apart from these, Perl uses no other environment variables, except to make them available to the program being executed, and to child processes. However, programs running setuid would do well to execute the following lines before doing anything else, just to keep people honest:</p> <pre><code>$ENV{PATH} = '/bin:/usr/bin'; # or whatever you need $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};</code></pre> </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>