← 返回命令列表

Linux command

perl 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Run a Perl script

perl [script.pl]

Execute a one-liner

perl -e 'print "Hello\n"'

In-place edit

perl -i -pe 's/old/new/g' [file]

In-place edit with backup

perl -i.bak -pe 's/old/new/g' [file]

Print specific columns

perl -ane 'print "$F[0]\n"' [file]

Check syntax

perl -c [script.pl]

Process input line by line

perl -ne 'print if /[pattern]/' [file]

Use a module

perl -MJSON -e 'print encode_json({key => "value"})'

说明

perl is the Perl 5 language interpreter. Perl is a general-purpose programming language originally developed for text manipulation, combining features from C, sed, awk, and shell scripting. The language excels at text processing with powerful built-in regular expression support. It is widely used for system administration, web development, network programming, and data processing. The Comprehensive Perl Archive Network (CPAN) provides a vast repository of reusable modules.

参数

-e _CODE_
Execute the given code as a one-liner. Multiple -e flags are allowed.
-E _CODE_
Like -e but enables all optional features (say, state, etc.).
-n
Wrap code in a while(<>) loop, reading input line by line without printing.
-p
Like -n but also prints $_ after each iteration.
-i_EXT_
In-place edit files. If extension given, creates backup with that suffix.
-a
Turn on autosplit mode (used with -n or -p). Splits each line into @F.
-F _PATTERN_
Specify the split pattern for autosplit mode (default: whitespace).
-l
Enable automatic line-ending processing. Strips newlines on input, adds on output.
-0_OCTAL_
Specify input record separator as octal value. -0777 slurps entire files.
-w
Enable warnings (prefer `use warnings;` in scripts).
-W
Enable all warnings unconditionally.
-c
Syntax check only; do not execute the program.
-M_MODULE_
Load a module before executing (equivalent to `use MODULE`).
-T
Enable taint mode for security. Untrusted data cannot affect the system.
-S
Use PATH to find the script. Emulates #! on platforms that don't support it.
-d
Run the program under the debugger.
-v
Print version and configuration summary.

FAQ

What is the perl command used for?

perl is the Perl 5 language interpreter. Perl is a general-purpose programming language originally developed for text manipulation, combining features from C, sed, awk, and shell scripting. The language excels at text processing with powerful built-in regular expression support. It is widely used for system administration, web development, network programming, and data processing. The Comprehensive Perl Archive Network (CPAN) provides a vast repository of reusable modules.

How do I run a basic perl example?

Run `perl [script.pl]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -e _CODE_ do in perl?

Execute the given code as a one-liner. Multiple -e flags are allowed.