perl基础知识02【代码执行格式】
2013-07-12 12:14
453 查看
[oracle@localhost ~]$ perl --help
Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-C[number/list] enables the listed Unicode features
-c check syntax only (runs BEGIN and CHECK blocks)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-e program one line of program (several -e's allowed, omit programfile)
#这个参数也常用,当在后面执行命令行时;如
[oracle@localhost ~]$ perl -e' print "ok\n"'
ok
-f don't do $sitelib/sitecustomize.pl at startup
-F/pattern/ split() pattern for -a switch (//'s are optional)
-i[extension] edit <> files in place (makes backup if extension supplied)
#直接在原文件上做修改!做时记得做个备份
-Idirectory specify @INC/#include directory (several -I's allowed)
-l[octal] enable line ending processing, specifies line terminator
-[mM][-]module execute "use/no module..." before executing program
-n assume "while (<>) { ... }" loop around program
#当作是循环,此选项经常使用,假定一个文本有10行内容,那么如果要处理这10行,你就要加上此参数;
-p assume loop like -n but print line also, like sed
#暂时未看出是什么用处的
-P run program through C preprocessor before compilation
#在编译之前通过C预处理器运行
-s enable rudimentary parsing for switches after programfile
#待确定
-S look for programfile using PATH environment variable
#它会去$PATH目录中去寻找你要执行的程序,而不会在默认的当前目录
-t enable tainting warnings
#开启损坏警告
-T enable tainting checks
#开启损坏核对
-u dump core after parsing program
[oracle@localhost ~]$ cat perl01
#!/usr/bin/perl
print "what\n";
[oracle@localhost ~]$ perl -u perl01
Aborted
-U allow unsafe operations
-v print version, subversion (includes VERY IMPORTANT perl info)
#直接输入perl -v 输出版本信息
-V[:variable] print configuration summary (or a single Config.pm variable)
#:直接输入perl -V 输出配置汇总
-w enable many useful warnings (RECOMMENDED)
[oracle@localhost ~]$ cat perl01
#!/usr/bin/perl
print what;
[oracle@localhost ~]$ perl perl01
[oracle@localhost ~]$ perl -w perl01 #因为没有在print内容上加引号的告警,虽然直接执行没有报错!
Unquoted string "what" may clash with future reserved word at perl01 line 2.
Name "main::what" used only once: possible typo at perl01 line 2.
print() on unopened filehandle what at perl01 line 2.
-W enable all warnings #同上 (-w)
-x[directory] strip off text before #!perl line and perhaps cd to directory
#格式类似于:perl -xzbkdir perl01 #其中zbkdir为一目录名,具体用处还不详;
-X disable all warnings
[oracle@localhost ~]$ perl -X perl01
[oracle@localhost ~]$
[oracle@localhost ~]$ cat perl01
use warnings;
#!/usr/bin/perl
print what;
[oracle@localhost ~]$ perl perl01
Unquoted string "what" may clash with future reserved word at perl01 line 3.
Name "main::what" used only once: possible typo at perl01 line 3.
print() on unopened filehandle what at perl01 line 3.
[oracle@localhost ~]$ perl -X perl01 #忽略里边use warnings的告警提示;
兴例:
(1)-ne
[oracle@localhost ~]$ cat >01.txt
first
second
third
[oracle@localhost ~]$
[oracle@localhost ~]$ perl -e '
> print;
> ' 01.txt
[oracle@localhost ~]$
[oracle@localhost ~]$ perl -ne'
> print;
> ' 01.txt
first
second
third
[oracle@localhost ~]$
#可以看到只有加入了-n选项后才能将文中的内容循环的输出;
(2)-i
#在原文件基础上直接修改
[oracle@localhost ~]$ perl -i -ne'
> s/first/last/ig;
> print;
> ' 01.txt
[oracle@localhost ~]$ cat 01.txt
last
second
third
#以上操作要切记备份,以免悲剧发生!
Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-C[number/list] enables the listed Unicode features
-c check syntax only (runs BEGIN and CHECK blocks)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-e program one line of program (several -e's allowed, omit programfile)
#这个参数也常用,当在后面执行命令行时;如
[oracle@localhost ~]$ perl -e' print "ok\n"'
ok
-f don't do $sitelib/sitecustomize.pl at startup
-F/pattern/ split() pattern for -a switch (//'s are optional)
-i[extension] edit <> files in place (makes backup if extension supplied)
#直接在原文件上做修改!做时记得做个备份
-Idirectory specify @INC/#include directory (several -I's allowed)
-l[octal] enable line ending processing, specifies line terminator
-[mM][-]module execute "use/no module..." before executing program
-n assume "while (<>) { ... }" loop around program
#当作是循环,此选项经常使用,假定一个文本有10行内容,那么如果要处理这10行,你就要加上此参数;
-p assume loop like -n but print line also, like sed
#暂时未看出是什么用处的
-P run program through C preprocessor before compilation
#在编译之前通过C预处理器运行
-s enable rudimentary parsing for switches after programfile
#待确定
-S look for programfile using PATH environment variable
#它会去$PATH目录中去寻找你要执行的程序,而不会在默认的当前目录
-t enable tainting warnings
#开启损坏警告
-T enable tainting checks
#开启损坏核对
-u dump core after parsing program
[oracle@localhost ~]$ cat perl01
#!/usr/bin/perl
print "what\n";
[oracle@localhost ~]$ perl -u perl01
Aborted
-U allow unsafe operations
-v print version, subversion (includes VERY IMPORTANT perl info)
#直接输入perl -v 输出版本信息
-V[:variable] print configuration summary (or a single Config.pm variable)
#:直接输入perl -V 输出配置汇总
-w enable many useful warnings (RECOMMENDED)
[oracle@localhost ~]$ cat perl01
#!/usr/bin/perl
print what;
[oracle@localhost ~]$ perl perl01
[oracle@localhost ~]$ perl -w perl01 #因为没有在print内容上加引号的告警,虽然直接执行没有报错!
Unquoted string "what" may clash with future reserved word at perl01 line 2.
Name "main::what" used only once: possible typo at perl01 line 2.
print() on unopened filehandle what at perl01 line 2.
-W enable all warnings #同上 (-w)
-x[directory] strip off text before #!perl line and perhaps cd to directory
#格式类似于:perl -xzbkdir perl01 #其中zbkdir为一目录名,具体用处还不详;
-X disable all warnings
[oracle@localhost ~]$ perl -X perl01
[oracle@localhost ~]$
[oracle@localhost ~]$ cat perl01
use warnings;
#!/usr/bin/perl
print what;
[oracle@localhost ~]$ perl perl01
Unquoted string "what" may clash with future reserved word at perl01 line 3.
Name "main::what" used only once: possible typo at perl01 line 3.
print() on unopened filehandle what at perl01 line 3.
[oracle@localhost ~]$ perl -X perl01 #忽略里边use warnings的告警提示;
兴例:
(1)-ne
[oracle@localhost ~]$ cat >01.txt
first
second
third
[oracle@localhost ~]$
[oracle@localhost ~]$ perl -e '
> print;
> ' 01.txt
[oracle@localhost ~]$
[oracle@localhost ~]$ perl -ne'
> print;
> ' 01.txt
first
second
third
[oracle@localhost ~]$
#可以看到只有加入了-n选项后才能将文中的内容循环的输出;
(2)-i
#在原文件基础上直接修改
[oracle@localhost ~]$ perl -i -ne'
> s/first/last/ig;
> print;
> ' 01.txt
[oracle@localhost ~]$ cat 01.txt
last
second
third
#以上操作要切记备份,以免悲剧发生!
相关文章推荐
- C#基础知识复习1代码规范-执行流程(c#)-面向对象-引用命名空间-封装-继承-访问修饰符-虚方法-静态成员-多态-抽象类等
- 通向往架构师之路之 用简单的代码写复杂的逻辑--基础知识运用
- Android第一行代码笔记 Activity的一些基础知识
- Java基础知识强化之IO流笔记72:NIO之 NIO核心组件(NIO使用代码示例)
- 02-1.Mongodb基础知识
- Android基础知识 有用代码片段
- 视频格式基础知识:让你了解MKV、MP4、H.265、码率\码流、多码流等等
- 搭建 Gtk2::Perl 单步执行代码的环境
- maven基础知识02---坐标和仓库
- 基础知识系列5--五大查找(二叉查找树代码未写)
- Python基础-文档测试(自动执行注释中的代码)
- Js_基础知识学习_02
- css中的一些基础知识-02
- android基础知识02——线程安全2:handler、message、runnable
- perl基础知识06【转义与元字符与特殊字符】
- SQL优化【基础02】 - 执行计划的执行先后顺序
- C基础 如何让代码只执行一次
- JavaWeb小项目涉及的基础知识02
- Java基础-代码执行顺序(重要)
- android基础知识02——线程安全4:HandlerThread