Shell中直接调用perl命令

本文详细介绍了Perl命令行选项的使用方法,包括如何通过-e选项快速执行Perl操作、如何使用-i选项替换原始文件等。此外,还列举了Perl 5命令行开关的各个选项及其用途,如用于语法检查的-c选项、用于指定调试行为的-D选项等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The -e option is handy for quick Perl operations from the command line. Want to change all instances of "oldstring" in Wiffle.bat to "newstrong"? Try

perl -i.old -p -e "s/ oldstring/ newstrong/g" wiffle.bat

This says: "Take each line of Wiffle.bat (-p); store the original in Wiffle.old (-i); substitute all instances of oldstring with newstrong (-e); write the result (-p) to the original file (-i)."

Other PERL command line options are:

Perl 5 Command-Line Switches

Option Arguments Purpose Notes
-0 octal character codeSpecify record separator Default is newline (/n)
-a noneAutomatically spli recordst Used with -n or or -p
-c noneCheck syntax onlyDo not execute
-d noneRun script using Perl debugger If Perl debugging option was included when Perl was installed
-D flagsSpecify debugging behavior See table 2
-e commandPass a command to Perl from the command line Useful for quick operations
-F regular expressionIf -a used Expression to split by default is white space
-i extensionReplace original file with results Useful for modifying contents of files
-I directorySpecify location of include files
-l octal character codeDrop newlines when used With -n and -p and use designated character as line- termination character
-n noneProcess the script using each specified file as an argument Used for performing the same set of actions on a set of files
-p noneSame as -n but each line is printed
-P noneRun the script through the C preprocessor before Perl compiles it
-s noneEnable passing of arbitrary switches to Perl Use -s -what -ever to have the Perl variables $what and $ever defined within your script
-S noneTell Perl to look along the path for the script
-T noneUse taint checking; don't evaluate expressions supplied on the command line
-u noneMake Perl dump core after compiling your script; intended to allow for generation of Perl executables Very messy; wait for the Perl compiler
-U noneUnsafe mode; overrides Perl's natural caution Don't use this!
-v nonePrint Perl version number
-w nonePrint warnings about script syntax Extremely useful, especially during development

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值