| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> perl >> Perl zuo wei ming ling xing shi yong cheng xu

Perl zuo wei ming ling xing shi yong cheng xu

2008-05-19 05:49:58 编辑來源:互联网 评论
 
 
 
本文为【Perl作为命令行实用程序】的拼音翻译版
  na xie jiang Perl yong zuo bian cheng yu yan de ren jing chang hu shi le :Perl yong zuo ming ling xing cao zuo de kuai su er you nan kan de jiao ben bian zhi yin qing shi shi hen you yong de 。 tong guo ming ling xing ,Perl jin yong yi xing jiu ke yi shi xian da duo shu qi ta yu yan xu yao shu ye dai ma cai neng wan cheng de ren wu 。 gen zhe Teodor, ta hui jiao gei nin yi xie you yong de shi li 。
  wei le wan cheng zhe yi pian how-to wen zhang , nin xu yao zai xi tong shang an zhuang Perl 5.6.0。 nin de xi tong zui hao an zhuang bi jiao xin (2000 huo geng xin ) de Linux huo Unix, dan shi qi ta cao zuo xi tong ye neng zhao yang gong zuo 。 suo you de shi li dou shi yong tcsh shell( jin guan bash ji qi ta shell ye neng gong zuo )。 sui ran zhe xie shi li ye xu ke yi he jiao zao ban ben de Perl、Linux ji qi ta cao zuo xi tong yi qi gong zuo , dan shi ru guo ta men bu neng yi qi gong zuo , na me ta men wu fa gong zuo de yuan yin ke yi zuo wei lian xi , rang du zhe qu jie jue 。
  wo xiang shuo de di yi dian shi : you jing yan de cheng xu yuan bu ying hui bi kuai su er you nan kan de jie jue fang an 。 zai qi ta zhuan lan wen zhang zhong , wo yi jing qiang tiao le wen dang bian zhi he che di xing 。 ben zhuan lan wen zhang jiang ji zhong zai bian cheng de xiao ji mian , qi zhong wen dang bian zhi shi ke xuan de , er ka fei yin que wu cong xuan ze 。 yin wei wo men yi jing shen xian qi zhong 。
  di er dian he di yi dian yi yang chong yao : kuai su er you nan kan de jie jue fang an hen nan zheng que wan cheng 。 ru guo nin zhi dao ru he ji lu 、 ce shi he tiao shi wan zheng de jiao ben , na me nin jiu fei chang you ke neng zai yi xing cheng xu zhong qu de cheng gong 。 ru guo nin bu zhi dao zen yang zuo , na me zhe jiu xiang shi qi tu yong fei yu lai kan dao hong shan shu ( er nin de ji neng jiu shi na tiao fei yu )。
  di yi bu , nin ying gai xue xi shell de te xing :Unix jiang ming ling xing shen shu chuan di gei Perl de fang shi ji zhe xie shen shu de Perl jie shi fang fa 。
  ming ling xing de shi zhi
  zai Unix zhong nin jiang kan dao ke zhi xing ren wu de gai nian , yi ge jin cheng tong chang shi zhuang ru nei cun de cheng xu 。 chu le chu shi jin cheng wai , jin cheng dou ke yi you qi ta jin cheng lai qi dong , chu shi jin cheng tong chang shi you nei gai ( you shi you nei gai jin cheng ) lai qi dong de 。 jiu yong hu de guan dian er yan , qi dong jin cheng xu yao shell huo qi dong cheng xu 。 yin ci , dang yong hu zai shell ming ling xing shu ru "xeyes" huo zhe cong qi dong cheng xu cai dan ( lei si yu GNOME ren wu lan ) xuan ze X Eyes ying yong cheng xu shi ,shell huo qi dong cheng xu chuang jian xin de jin cheng yi yun xing gai cheng xu 。
  jin cheng huo de ming ling xing shen shu 。 yin ci , li ru ,"perl" he "perl -w" shi dui tong yi ge cheng xu de liang zhong bu tong tiao yong 。 zai nei bu ,Perl( lei si yu C) jiang shen shu chuan di gei ta yong @ARGV shu zu jie shi de jiao ben 。 dan shi he C bu tong de shi ,Perl tou tou di cong jiao ben zhong " qie qu " qi zhong yi xie shen shu yi yong yu zi ji de yong tu 。 li ru , zheng zai jie shi de jiao ben kan bu dao chuan gei Perl jie shi qi de "-w" shen shu , chu fei jiao ben kan lai xu yao ta 。shell yong kong ge zi fu ge kai shen shu 。
  chuan gei Perl de "-e" shen shu gao su Perl huo qu ming ling xing zhong "-e" hou de ren he nei rong bing jiang ta dang zuo jiao ben lai yun xing 。"-M" shen shu biao shi huo qu qi hou de ren he nei rong bing jiang gai nei rong zuo wei mo kuai dao ru , lei si yu zheng gui jiao ben zhong de "use ModuleName"。 qing shen yue perldoc perlrun ye mian yi huo qu you guan Perl bi xu cong ming ling xing ti gong de kai guan de geng duo xin xi 。
  ke neng zui hao zai zhe li ju xie shi li 。 gen ju ben zhuan lan wen zhang de jing shen , rang wo men shi yong yi xing cheng xu 。 jiao ben de -MData:umper -e'print Dumper -@ARGV' bu fen zhi shi da yin chu le @ARGV shu zu de nei rong 。
  qing dan 1. ming ling xing shen shu
  # at the command line, type each line after the ''
  # and you'll get the output that
  # follows it
  # print the @ARGV contents with no program arguments
  perl -MData:umper -e'print Dumper \@ARGV'
  $VAR1 = [];
  # print the @ARGV contents with arguments "a" and "b"
  perl -MData:umper -e'print Dumper \@ARGV' a b
  $VAR1 = [
  'a',
  'b'
  ];
  # print the @ARGV contents with warnings on, and arguments "a" and "b"
  perl -w -MData:umper -e'print Dumper \@ARGV' a b
  $VAR1 = [
  'a',
  'b'
  ];
  # print the @ARGV contents with arguments "a", "b", and "-w"
  # note how the -w is not stolen by Perl if it follows arguments
  # that Perl knows it doesn't want
  perl -MData:umper -e'print Dumper \@ARGV' a b -w
  $VAR1 = [
  'a',
  'b',
  '-w'
  ];
  Here is the final line that includes some chu fei nin de shell xian zhi le shen shu de shu liang huo chang du , bu ran nin ke yi xiang Perl chuan di ren yi shu liang de shen shu 。 zai Perl zhong da kai shen qi de wen jian ju bing (filehandle), zhe hui jiang chuan song gei Perl de mei ge shen shu zuo wei wen jian ming da kai bing zhu xing du qu mei ge wen jian de nei rong 。 que sheng qing kuang xia ,$_ bian liang hui bao cun mei yi xing 。Shell shi yin hao zhi jian de suo you nei rong dou cheng wei yi ge shen shu 。 zhe jiu shi wei shen me zai qing dan 1 zhong wo men ke yi xie cheng -e'print Dumper \@ARGV' bing qie Perl ke yi jiang qi kan cheng dan ge yi xing cheng xu jiao ben de yuan yin 。 dan yin hao geng hao , yin wei shi yong dan yin hao hou nin ke yi zai yi xing cheng xu nei shi yong shuang yin hao 。Perl zhong de shuang yin hao yong yu jie shi shuang yin hao zhi jian de ren he nei rong 。 ling yi ge shi li huo xu hui you zhu yu jin yi bu shuo ming zhe yi dian : qing dan 2. dan yin hao vs. shuang yin hao # print the Perl process ID, followed by a newlineperl -e'print "$$\n"'2063# error: the first two double quotes go together, the rest is passed# to the script directlyperl -e"print "$$\n""Bareword found where operator expected at -e line 1, near "1895n"(Missing operator before n?)syntax error at -e line 1, next token ???Execution of -e aborted due to compilation errors. yong bash bi yong tcsh yao hao xie , yin wei bash yuan xu nei bu de shuang yin hao yong \ zi fu jin xing zhuan yi 。 dan shi shell reng ran zai jiang shuang yin hao nei de $$ chuan di gei Perl zhi qian dui qi jin xing jie shi 。 jie lun shi : bu yao shi yong shuang yin hao lai zhi ding yi -e kai shi de yi xing cheng xu jiao ben shen shu 。 qing shen yue perldoc perlrun yi huo qu geng duo de xiang xi xin xi , dan shi nin zhu yao ying qing chu shen me zai xi tong shang you xiao bing jian chi xia qu 。 dao mu qian wei zhi nin yi jing le jie le -e he -M kai guan suo qi de zuo yong : dao ru mo kuai he yun xing yu ju 。 xia mian wo lie chu le yi xie you yong de qi ta kai guan ; wei le bu ba nin gao hu tu , suo yi sheng lue le na xie geng fu duo de kai guan 。 qing shen yue perldoc perlrun yi huo qu wan zheng de lie biao he yi xie shi yong xiang fa 。 zheng jie xing -w da kai jing gao -Mstrict da kai yan ge bian yi zhi shi (pragma) shu ju -0( zhe shi ge ling ) zhi ding shu ru ji lu fen ge fu -a jiang shu ju fen ge cheng ming wei @F de shu zu -F zhi ding fen ge shi -a shi yong de mo shi ( qing shen yue perldoc -f split)-i zai shi dang de wei zhi bian ji wen jian ( qing shen yue perldoc perlrun yi huo qu da liang xiang xi xin xi )-n shi yong jiang suo you @ARGV shen shu dang zuo wen jian lai zhu ge yun xing -p he -n yi yang , dan shi huan hui da yin $_ de nei rong zhi xing kong zhi -e zhi ding zi fu chuan yi zuo wei jiao ben ( duo ge zi fu chuan die jia ) zhi xing -M dao ru mo kuai -I zhi ding mu lu yi sou suo biao zhun wei zhi qian de mo kuai wen jian cao zuo jia ding nin zai yi ge mu lu zhong you yi xie wen jian xu yao yong te ding de fang shi chong ming ming 。 li ru , suo you bao han dan ci "aaa" de wen jian ying jin xing chong ming ming , yong dan ci "bbb" jin xing dai ti 。 wo men jiang bu shi yong Unix"mv" ming ling , yin wei yong Perl de rename() han shu lai chong ming ming wen jian yi jing xiang dang bu cuo le ( qing shen yue perldoc -f rename yi huo qu dang shi yong rename() chu wen ti shi de xiang xi xin xi )。 qing shen yue qing dan 3 yi huo qu jiang wen jian cong aaa chong ming ming wei bbb de yi xing cheng xu jiao ben 。find . ming ling da yin chu dang qian mu lu xia de suo you wen jian he mu lu lie biao 。 ru guo nin zhi xiang yao cha kan wen jian , na me jiu gei find tian jia "-type f" shen shu 。 huo qu find de shu chu ( yi ge wen jian lie biao ) bing jiang qi chuan di gei yi xing cheng xu 。 yi xing jiao ben shi yong -ne shen shu , gai yi wei zhe ta hui bei chong xie cheng : qing dan 4. jiang wen jian cong aaa chong ming ming wei bbb( yi fen jie )while (){chomp; # trim the newline from the filenamenext unless -e; # the filename ($_) must exist$oldname = $_; # $oldname is now $_s/aaa/bbb/; # change all "aaa" to "bbb" in $_next if -e; # the new filename mustn't existrename $oldname, $_; # rename the old to the new name} zheng ru nin suo kan dao de na yang , zhe shi ge xiang dang fu duo de qi xing jiao ben 。-n kai guan jian hua le hen duo dong xi 。 dan shi jin guan ru ci , nin huan shi bi xu zhi dao $_ bian liang he s/// ji -e yun suan fu ( qing shen yue perldoc perlop ye mian yi huo qu xiang xi xin xi )。File::Find biao zhun Perl mo kuai ben lai ke yi dai ti Unix find ming ling yong yu jin xing wen jian cha zhao , dan shi jiao ben ye hui sui zhi bian de tai da er bu zai shi yi xing cheng xu le 。 yi xing cheng xu qiao miao di ping heng le you yong xing he fu duo xing , nin bi xu zhun bei hao zai xu yao shi jiang ta men chong xie cheng shi ji jiao ben , er bu ying rang cheng xu guo yu ma fan er wu fa kong zhi 。 xia mian shi wen jian chu li de ling yi ge shi li : yong yi zhi de ming ming jie gou liu lan MP3 wen jian de mu lu bing chou qu zhuan ji ming 。 rang wo men jia she wen jian ming shi "Artist-Album-Track#-Song.mp3"。 qing dan 5. cha zhao Artist-Album-Track#-Song.mp3 de zhuan ji ming find . -name "*.mp3" | perl -pe 's/.\/\w+-(\w+)-.*/$1/' | sort | uniq zhe ge jiao ben fei chang jian dan 。 ta yi kao find de xing wei , zong shi zai mei ge wen jian ming qian da yin "./"。 sui hou ta jin yong zhuan ji ming dai ti $_, bing qie -p kai guan zi dong da yin zhuan ji ming 。 zui hou , an shun xu de sort he uniq que bao le chong fu de zhuan ji ming zhi da yin yi ci 。 suo you de find、sort he uniq tiao yong dou ke yi yong Perl wan cheng , dan shi zai cao zuo xi tong yi jing wei wo men bian xie le zhe yi qie shi wei he huan fan nao ne ? zuo wei lian xi zhe hui hen you qu , dan shi shi ji shang yi xing cheng xu ke neng hui bian cheng 20-30 xing bu bi yao de dai ma 。 rang wo men fen jie Perl jiao ben ( yong yi zhong jian hua de fang shi - sheng lue -p kai guan de yi xie fu duo xing ): qing dan 6. cha zhao Artist-Album-Track#-Song.mp3 de zhuan ji ming ( yi fen jie )while (){s/.\/\w+-(\w+)-.*/$1/; # extract the album name into $_} continue{print; # print the album name} ci wai , qing zhu yi Perl shi ru he cheng wei find、sort he uniq zhi jian de zhong jian gong ju de 。 bu bi chang shi yong Perl bian xie suo you dong xi 。 nin ke yi zhe me zuo , you shi ye bi xu zhe me zuo , dan yi xing cheng xu ke yi chong yong 。 huan you , kan kan zheng ze biao da shi shi duo me de jian dan 。 dang ran , ru guo MP3 wen jian wei zheng que ming ming , na me wo men ke neng hui huo de yi xie yi chang de zhuan ji ming , dan shi zhe zhi de qu jin li wan shan zheng ze biao【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   na xie jiang Perl yong zuo bian cheng yu yan de ren jing chang hu shi le :Perl yong zuo ming ling xing cao zuo de kuai su er you nan kan de jiao ben bian zhi yin qing shi shi hen you yong de 。 tong guo ming ling xing ,Perl jin yong yi xing jiu ke yi shi xian da duo shu qi ta yu yan xu yao shu ye dai ma cai neng wan cheng de ren wu 。 gen zhe Teodor, ta hui jiao gei nin yi xie you yong de shi li 。    wei le wan cheng zhe yi pian how-to wen zhang , nin xu yao zai xi tong shang an zhuang Perl 5.6.0。 nin de xi tong zui hao an zhuang bi jiao xin (2000 huo geng xin ) de Linux huo Unix, dan shi qi ta cao zuo xi tong ye neng zhao yang gong zuo 。 suo you de shi li dou shi yong tcsh shell( jin guan bash ji qi ta shell ye neng gong zuo )。 sui ran zhe xie shi li ye xu ke yi he jiao zao ban ben de Perl、Linux ji qi ta cao zuo xi tong yi qi gong zuo , dan shi ru guo ta men bu neng yi qi gong zuo , na me ta men wu fa gong zuo de yuan yin ke yi zuo wei lian xi , rang du zhe qu jie jue 。    wo xiang shuo de di yi dian shi : you jing yan de cheng xu yuan bu ying hui bi kuai su er you nan kan de jie jue fang an 。 zai qi ta zhuan lan wen zhang zhong , wo yi jing qiang tiao le wen dang bian zhi he che di xing 。 ben zhuan lan wen zhang jiang ji zhong zai bian cheng de xiao ji mian , qi zhong wen dang bian zhi shi ke xuan de , er ka fei yin que wu cong xuan ze 。 yin wei wo men yi jing shen xian qi zhong 。    di er dian he di yi dian yi yang chong yao : kuai su er you nan kan de jie jue fang an hen nan zheng que wan cheng 。 ru guo nin zhi dao ru he ji lu 、 ce shi he tiao shi wan zheng de jiao ben , na me nin jiu fei chang you ke neng zai yi xing cheng xu zhong qu de cheng gong 。 ru guo nin bu zhi dao zen yang zuo , na me zhe jiu xiang shi qi tu yong fei yu lai kan dao hong shan shu ( er nin de ji neng jiu shi na tiao fei yu )。    di yi bu , nin ying gai xue xi shell de te xing :Unix jiang ming ling xing shen shu chuan di gei Perl de fang shi ji zhe xie shen shu de Perl jie shi fang fa 。    ming ling xing de shi zhi    zai Unix zhong nin jiang kan dao ke zhi xing ren wu de gai nian , yi ge jin cheng tong chang shi zhuang ru nei cun de cheng xu 。 chu le chu shi jin cheng wai , jin cheng dou ke yi you qi ta jin cheng lai qi dong , chu shi jin cheng tong chang shi you nei gai ( you shi you nei gai jin cheng ) lai qi dong de 。 jiu yong hu de guan dian er yan , qi dong jin cheng xu yao shell huo qi dong cheng xu 。 yin ci , dang yong hu zai shell ming ling xing shu ru "xeyes" huo zhe cong qi dong cheng xu cai dan ( lei si yu GNOME ren wu lan ) xuan ze X Eyes ying yong cheng xu shi ,shell huo qi dong cheng xu chuang jian xin de jin cheng yi yun xing gai cheng xu 。    jin cheng huo de ming ling xing shen shu 。 yin ci , li ru ,"perl" he "perl -w" shi dui tong yi ge cheng xu de liang zhong bu tong tiao yong 。 zai nei bu ,Perl( lei si yu C) jiang shen shu chuan di gei ta yong @ARGV shu zu jie shi de jiao ben 。 dan shi he C bu tong de shi ,Perl tou tou di cong jiao ben zhong " qie qu " qi zhong yi xie shen shu yi yong yu zi ji de yong tu 。 li ru , zheng zai jie shi de jiao ben kan bu dao chuan gei Perl jie shi qi de "-w" shen shu , chu fei jiao ben kan lai xu yao ta 。shell yong kong ge zi fu ge kai shen shu 。    chuan gei Perl de "-e" shen shu gao su Perl huo qu ming ling xing zhong "-e" hou de ren he nei rong bing jiang ta dang zuo jiao ben lai yun xing 。"-M" shen shu biao shi huo qu qi hou de ren he nei rong bing jiang gai nei rong zuo wei mo kuai dao ru , lei si yu zheng gui jiao ben zhong de "use ModuleName"。 qing shen yue perldoc perlrun ye mian yi huo qu you guan Perl bi xu cong ming ling xing ti gong de kai guan de geng duo xin xi 。    ke neng zui hao zai zhe li ju xie shi li 。 gen ju ben zhuan lan wen zhang de jing shen , rang wo men shi yong yi xing cheng xu 。 jiao ben de -MData:umper -e'print Dumper -@ARGV' bu fen zhi shi da yin chu le @ARGV shu zu de nei rong 。    qing dan 1. ming ling xing shen shu   # at the command line, type each line after the ''   # and you'll get the output that   # follows it   # print the @ARGV contents with no program arguments    perl -MData:umper -e'print Dumper \@ARGV'   $VAR1 = [];   # print the @ARGV contents with arguments "a" and "b"    perl -MData:umper -e'print Dumper \@ARGV' a b   $VAR1 = [   'a',   'b'   ];   # print the @ARGV contents with warnings on, and arguments "a" and "b"    perl -w -MData:umper -e'print Dumper \@ARGV' a b   $VAR1 = [   'a',   'b'   ];   # print the @ARGV contents with arguments "a", "b", and "-w"   # note how the -w is not stolen by Perl if it follows arguments   # that Perl knows it doesn't want    perl -MData:umper -e'print Dumper \@ARGV' a b -w   $VAR1 = [   'a',   'b',   '-w'   ];   Here is the final line that includes some    chu fei nin de shell xian zhi le shen shu de shu liang huo chang du , bu ran nin ke yi xiang Perl chuan di ren yi shu liang de shen shu 。 zai Perl zhong da kai shen qi de wen jian ju bing (filehandle), zhe hui jiang chuan song gei Perl de mei ge shen shu zuo wei wen jian ming da kai bing zhu xing du qu mei ge wen jian de nei rong 。 que sheng qing kuang xia ,$_ bian liang hui bao cun mei yi xing 。  Shell shi yin hao zhi jian de suo you nei rong dou cheng wei yi ge shen shu 。 zhe jiu shi wei shen me zai qing dan 1 zhong wo men ke yi xie cheng -e'print Dumper \@ARGV' bing qie Perl ke yi jiang qi kan cheng dan ge yi xing cheng xu jiao ben de yuan yin 。 dan yin hao geng hao , yin wei shi yong dan yin hao hou nin ke yi zai yi xing cheng xu nei shi yong shuang yin hao 。Perl zhong de shuang yin hao yong yu jie shi shuang yin hao zhi jian de ren he nei rong 。 ling yi ge shi li huo xu hui you zhu yu jin yi bu shuo ming zhe yi dian :   qing dan 2. dan yin hao vs. shuang yin hao   # print the Perl process ID, followed by a newline  perl -e'print "$$\n"'  2063  # error: the first two double quotes go together, the rest is passed  # to the script directly  perl -e"print "$$\n""  Bareword found where operator expected at -e line 1, near "1895n"  (Missing operator before n?)  syntax error at -e line 1, next token ???  Execution of -e aborted due to compilation errors.   yong bash bi yong tcsh yao hao xie , yin wei bash yuan xu nei bu de shuang yin hao yong \ zi fu jin xing zhuan yi 。 dan shi shell reng ran zai jiang shuang yin hao nei de $$ chuan di gei Perl zhi qian dui qi jin xing jie shi 。 jie lun shi : bu yao shi yong shuang yin hao lai zhi ding yi -e kai shi de yi xing cheng xu jiao ben shen shu 。 qing shen yue perldoc perlrun yi huo qu geng duo de xiang xi xin xi , dan shi nin zhu yao ying qing chu shen me zai xi tong shang you xiao bing jian chi xia qu 。   dao mu qian wei zhi nin yi jing le jie le -e he -M kai guan suo qi de zuo yong : dao ru mo kuai he yun xing yu ju 。 xia mian wo lie chu le yi xie you yong de qi ta kai guan ; wei le bu ba nin gao hu tu , suo yi sheng lue le na xie geng fu duo de kai guan 。 qing shen yue perldoc perlrun yi huo qu wan zheng de lie biao he yi xie shi yong xiang fa 。   zheng jie xing   -w   da kai jing gao   -Mstrict   da kai yan ge bian yi zhi shi (pragma)   shu ju   -0  ( zhe shi ge ling ) zhi ding shu ru ji lu fen ge fu   -a   jiang shu ju fen ge cheng ming wei @F de shu zu   -F   zhi ding fen ge shi -a shi yong de mo shi ( qing shen yue perldoc -f split)  -i   zai shi dang de wei zhi bian ji wen jian ( qing shen yue perldoc perlrun yi huo qu da liang xiang xi xin xi )  -n   shi yong jiang suo you @ARGV shen shu dang zuo wen jian lai zhu ge yun xing   -p   he -n yi yang , dan shi huan hui da yin $_ de nei rong    zhi xing kong zhi   -e   zhi ding zi fu chuan yi zuo wei jiao ben ( duo ge zi fu chuan die jia ) zhi xing   -M   dao ru mo kuai   -I   zhi ding mu lu yi sou suo biao zhun wei zhi qian de mo kuai    wen jian cao zuo    jia ding nin zai yi ge mu lu zhong you yi xie wen jian xu yao yong te ding de fang shi chong ming ming 。 li ru , suo you bao han dan ci "aaa" de wen jian ying jin xing chong ming ming , yong dan ci "bbb" jin xing dai ti 。 wo men jiang bu shi yong Unix"mv" ming ling , yin wei yong Perl de rename() han shu lai chong ming ming wen jian yi jing xiang dang bu cuo le ( qing shen yue perldoc -f rename yi huo qu dang shi yong rename() chu wen ti shi de xiang xi xin xi )。   qing shen yue qing dan 3 yi huo qu jiang wen jian cong aaa chong ming ming wei bbb de yi xing cheng xu jiao ben 。  find . ming ling da yin chu dang qian mu lu xia de suo you wen jian he mu lu lie biao 。 ru guo nin zhi xiang yao cha kan wen jian , na me jiu gei find tian jia "-type f" shen shu 。 huo qu find de shu chu ( yi ge wen jian lie biao ) bing jiang qi chuan di gei yi xing cheng xu 。   yi xing jiao ben shi yong -ne shen shu , gai yi wei zhe ta hui bei chong xie cheng :   qing dan 4. jiang wen jian cong aaa chong ming ming wei bbb( yi fen jie )  while ()  {  chomp; # trim the newline from the filename  next unless -e; # the filename ($_) must exist  $oldname = $_; # $oldname is now $_  s/aaa/bbb/; # change all "aaa" to "bbb" in $_  next if -e; # the new filename mustn't exist  rename $oldname, $_; # rename the old to the new name  }   zheng ru nin suo kan dao de na yang , zhe shi ge xiang dang fu duo de qi xing jiao ben 。-n kai guan jian hua le hen duo dong xi 。 dan shi jin guan ru ci , nin huan shi bi xu zhi dao $_ bian liang he s/// ji -e yun suan fu ( qing shen yue perldoc perlop ye mian yi huo qu xiang xi xin xi )。File::Find biao zhun Perl mo kuai ben lai ke yi dai ti Unix find ming ling yong yu jin xing wen jian cha zhao , dan shi jiao ben ye hui sui zhi bian de tai da er bu zai shi yi xing cheng xu le 。   yi xing cheng xu qiao miao di ping heng le you yong xing he fu duo xing , nin bi xu zhun bei hao zai xu yao shi jiang ta men chong xie cheng shi ji jiao ben , er bu ying rang cheng xu guo yu ma fan er wu fa kong zhi 。   xia mian shi wen jian chu li de ling yi ge shi li : yong yi zhi de ming ming jie gou liu lan MP3 wen jian de mu lu bing chou qu zhuan ji ming 。 rang wo men jia she wen jian ming shi "Artist-Album-Track#-Song.mp3"。   qing dan 5. cha zhao Artist-Album-Track#-Song.mp3 de zhuan ji ming   find . -name "*.mp3" | perl -pe 's/.\/\w+-(\w+)-.*/$1/' | sort | uniq   zhe ge jiao ben fei chang jian dan 。 ta yi kao find de xing wei , zong shi zai mei ge wen jian ming qian da yin "./"。 sui hou ta jin yong zhuan ji ming dai ti $_, bing qie -p kai guan zi dong da yin zhuan ji ming 。 zui hou , an shun xu de sort he uniq que bao le chong fu de zhuan ji ming zhi da yin yi ci 。 suo you de find、sort he uniq tiao yong dou ke yi yong Perl wan cheng , dan shi zai cao zuo xi tong yi jing wei wo men bian xie le zhe yi qie shi wei he huan fan nao ne ? zuo wei lian xi zhe hui hen you qu , dan shi shi ji shang yi xing cheng xu ke neng hui bian cheng 20-30 xing bu bi yao de dai ma 。   rang wo men fen jie Perl jiao ben ( yong yi zhong jian hua de fang shi - sheng lue -p kai guan de yi xie fu duo xing ):   qing dan 6. cha zhao Artist-Album-Track#-Song.mp3 de zhuan ji ming ( yi fen jie )  while ()  {  s/.\/\w+-(\w+)-.*/$1/; # extract the album name into $_  } continue  {  print; # print the album name  }   ci wai , qing zhu yi Perl shi ru he cheng wei find、sort he uniq zhi jian de zhong jian gong ju de 。 bu bi chang shi yong Perl bian xie suo you dong xi 。 nin ke yi zhe me zuo , you shi ye bi xu zhe me zuo , dan yi xing cheng xu ke yi chong yong 。 huan you , kan kan zheng ze biao da shi shi duo me de jian dan 。 dang ran , ru guo MP3 wen jian wei zheng que ming ming , na me wo men ke neng hui huo de yi xie yi chang de zhuan ji ming , dan shi zhe zhi de qu jin li wan shan zheng ze biao   
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
可爱小魔女
夏日小桃红
琦吖囡半熟乖巧清新写真
天使的微笑
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有