加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl基础知识02【代码执行格式】

发布时间:2020-12-16 00:11:08 所属栏目:大数据 来源:网络整理
导读:[oracle@localhost ~]$ perl --help Usage: perl [switches] [--] [programfile] [arguments] ? -0[octal]?????? specify record separator (,if no argument) ? -a????????????? autosplit mode with -n or -p (splits $_ into @F) ? -C[number/list] ena
[oracle@localhost ~]$ perl --help

Usage: perl [switches] [--] [programfile] [arguments]
? -0[octal]?????? specify record separator (,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 "okn"'
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 "whatn";
[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

#以上操作要切记备份,以免悲剧发生!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读