Linux and Unix perl command

Quick links

About perl
Syntax
Examples
Where to obtain Perl
Related commands
Linux and Unix main page

About perl

Perl is a programming language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).

Syntax

perl [-s] [-T] [-u] [-U] [-h] [-v] [-V[:configvar] ] [-c] [-w] [-d[:debugger] ] 
     [ -D[number/list] ] [-p] [-n] [-a] [ -F pattern ] [ -l[octal] ] 
     [-0[octal] ] [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ]  -P] 
     [-S] [-x[dir] ] [ -i[extension] ]  -e 'command'] [ -- ] 
     [programfile] [argument]
-s Enables rudimentary option parsing for options on the command line after the script name but before any file name arguments (or before a --).
-T Forces "taint" checks to be turned on so you can test them.
-u
-U Allows perl to do unsafe operations.
-h
-v Prints the version and patch level configuration of your perl executable.
-V[:conigvar] Prints summary of the major perl configuration values and the current value of @INC.
-c Checks the syntax of the script and then exits without executing it.
-w Prints warnings about variable names that are mentioned only once, and scalar variables that are used before being set.
-d Runs the script under the perl debugger
-D

Sets debugging flags. To turn on debugging flags, you can either specify a number which is the total of the numeric values of the desired flags (for example, -D14 turns on the Trace Execution, Label Stack Processing, and Stack Snapshots flags) or a list of the letters associated with those flags (for example, -Dtls is the same as -D14). Another nice value is -Dx, which lists your compiled syntax tree. And -Dr displays compiled regular expressions. The available flags are:

1 p Tokenizing and parsing
2 s Stack snapshots
4 l Lable stack processing
8 t Trace execution
16 o Operator node construction
32 c String/numeric conversions
64 p Print processor command for -P
128 m Memory allocation
256 f Format processing
512 r Regular expression parsing
1024 x Syntax tree dump
2048 u Tainting checks
4096 L Memory leaks (not supported with later versions)
8192 H Hash dump -- usurps values ()
16384 X Scratchpad allocation
32768 D Cleaning up
-p assumes the following loop around your script.

while (<>) {
# your script goes here
} continue {
print or die "-p destination: $!\n";
}

-n Assumes the following loop around your script.

while (<>) {
# your script goes here
 }

-a Turns on autosplit mode when used with a -n or -p.
-F pattern Specifies a pattern expression to split on
-l octal Enables automatic line-ending processing.
-0 octal Specifies the input record separator ($/) as an octal number. If there are no digits, the null character is the separator. Other options may precede or follow the digits.
-I dir Prepends directory to the search path for modules (@INC)
-m module Executes use module (); before executing the script.
-M 'module' executes use module ; before executing the script.
-P Runs your script through the preprocessor script cppstdin before compilation by perl.
-S Uses the PATH environment variable to search for the script (unless the name of the script starts with a slash).
-x dir Tells perl that the script is embedded in a message.
-i extension specifies that files processed by the <> construct are to be edited in-place.
-e command Specifies a line of script.
--
programfile Name of the perl program

Examples

perl myscript.cgi -d

Run a debug though the CGI / Perl Script myscript.cgi and if any errors are reported stop and report them else wise run through the complete script.

Where to obtain perl

Perl is available in a wide range of operating systems, below is a listing of operating systems which currently support Perl or have planned versions of Perl being released for them. Versions, additional information and downloads can be found at: http://www.perl.com/CPAN/ports/index.html

AIX Linux SCO ODT/OSR A/UX MachTen
Solaris BeOS MPE/iX SunOS BSD/OS
NetBSD SVR4 DG/UX NextSTEP Tru64
DomainOS OpenBSD Ultrix DOS DJGPP OpenSTEP
UNICOS DYNIX/ptx OS/2 VMS FreeBSD
OS390 VOS HP-UX PowerMAX Windows 3.1
Hurd QNX Windows 95 Windows 98 Windows NT
3b1 FPS Plan 9 AmigaOS GENIX
PowerUX ConvexOS Greenhills RISC/os CX/UX
ISC Stellar DC/OSx MachTen 68k SVR2
DDE SMES MiNT TI1500 DOS EMX MPC
TitanOS Dynix NEWS-OS UNICOS/mk EP/IX
Opus Unisys Dynix Esix Unixware BS2000
Netware Rhapsody VM/ESA

See the Perl definition for an example of a Perl script and all related terms.

Related commands

a2p
s2p