| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> perl >> shi he chu xue zhe de Perl de wen jian cao zuo (2)

shi he chu xue zhe de Perl de wen jian cao zuo (2)

2008-05-19 06:25:50 编辑來源:互联网 评论
 
 
 
本文为【适合初学者的Perl的文件操作(2)】的拼音翻译版
  du ru duo ge ji lu
  ru guo ni tiao yong , fan hui wen jian zhong sheng yu de ji lu 。 ru guo ni chu yu wen jian yi , ze fan hui kong biao :
  @records = ;
  if (@records) {
  print "There were ", scalar(@records), " records read.n";
  }
  zai xia mian de yi bu zhong , jin xing fu zhi he ce shi liang xiang gong zuo :
  if (@records = ) {
  print "There were ", scalar(@records), " records read.n";
  }
  chomp() ye ke shi yong dui shu zu cao zuo :
  @records = ;
  chomp(@records);
  dui yu ren he biao da shi , dou ke yi jin xing chomp cao zuo , gu ni ke yi zai xia mian de yi bu zhong zhe yang xie :
  chomp(@records = );
  shen me shi ji lu ?
  ji lu de que sheng ding yi wei :“ xing ”。
  ji lu de ding yi you $/ bian liang kong zhi de , gai bian liang cun fang suo shu ru de ji lu de fen ge fu , yin wei huan xing fu zi fu ( gen ju ding yi !) shi yong lai fen ge xing de , gu qi que sheng zhi wei chuan “n”。
  li ru , ni ke yi yong ren he ni xiang yao ti huan de fu hao lai dai ti “n”。
  $/ = ";";
  $record = ; # du ru xia yi ge yong fen hao fen ge de ji lu
  $/ ke yi qu qi ta liang ge you qu de zhi : kong chuan ("") he undef。
  du ru duan luo
  $/ ="" de xie fa shi yong lai zhi shi Perl du ru duan luo de , duan luo shi you liang ge huo liang ge yi shang de huan xing fu gou cheng de wen ben kuai 。 zhe bu tong yu she zhi wei "nn", hou zhe jin du ru you liang xing zu cheng de wen ben kuai 。 zai zhe zhong qing kuang xia , jiang chu xian zhe yang yi ge wen ti : ru guo you lian xu de kong xing cun zai , li ru “textnnnn”, ni ji ke yi ba ta jie shi wei yi ge duan luo ("text"), ye ke yi jie shi wei liang ge duan luo ("text", hou mian gen liang ge huan xing fu , yi ji yi ge kong duan luo , hou mian gen liang ge kong xing 。)
  zai du ru wen ben shi , di er ge jie shi yong tu bu da 。 ru guo ni zheng zai du de duan luo chu xian shang shu qing kuang , ni bu bi guo lv chu “ kong ” duan luo 。
  $/ = "nn";
  while () {
  chomp;
  next unless length; # tiao guo kong duan
  # ...
  }
  ni ke yi ba $/ she zhi wei undef, ta yong yu du ru hou mian gen zhe liang ge huo duo ge huan xing fu zu cheng de duan luo : undef $/;
  while () {
  chomp;
  # ...
  }
  du ru zheng ge wen jian
  $/ de qi ta you qu de zhi wei undef。 ru guo she zhi wei gai zhi , jiu jiang gao su Perl, du ming ling jiang ba wen jian de sheng yu bu fen zuo wei yi ge chuan fan hui :
  undef $/;
  $file = ;
  yin wei gai bian le $/ de zhi , jiang hui ying xiang yi hou de mei ci du cao zuo , er bu jin shi xia yi ge du cao zuo 。 tong chang , ni xu yao jiang gai cao zuo xian zhi zai ju bu 。 tong guo xia mian de li zi , ke yi ba wen jian ju bing de nei rong du ru dao yi ge chuan zhong :
  {
  local $/ = undef;
  $file = ;
  }
  ji zhu :Perl bian liang ke du ru hen chang de chuan 。 jin guan ni de wen jian da xiao bu ke yi chao chu ni de xu ni nei cun rong liang de xian du , ni reng ke yi du ru jin ke neng duo de shu ju 。
  yong zheng ze biao da shi dui wen jian jin xing cao zuo
  yi dan ni you ge bao han le zheng ge chuan de bian liang , ni ke yi shi yong zheng ze biao da shi , dui zheng ge wen jian jin xing cao zuo , er bu shi dui wen jian zhong de mou ge kuai jin xing cao zuo 。 you liang ge you yong de zheng ze biao da shi biao ji /s he /m。 yi ban ,Perl de zheng ze biao da shi dui xing jin xing chu li , ni ke yi zhe yang xie :
  undef $/;
  $line = ;
  if ($line =~ /(b.*grass)$/) {
  print "found $1n";
  }
  ru guo ba wo men de wen jian tian ru ru xia nei rong :
  browngrass
  bluegrass
  ze shu chu wei :
  found bluegrass
  ta mei you zhao dao “browngrass”, zhe shi yin wei $ jin zai chuan yi xun zhao qi pi pei , ( huo zhe zai chuan jie shu qian de yi xing )。 ru guo zai bao han hen duo xing de chuan zhong , yong "^" he "$" lai pi pei ,, wo men ke yi shi yong /m ("multiline") xuan xiang :
  if ($line =~ /(b.*grass)$/m) {}
  xian zai cheng xu hui ba ru xia de xin xi shu chu :
  found browngrass
  lei si di , ju dian ke yi pi pei chu le huan xing fu zhi wai de suo you zi fu :
  while () {
  if (/19(.*)$/) {
  if ($1 < 20) {
  $year = 2000+$1;
  } else {
  $year = 1900+$1;
  }
  }
  }
  ru guo wo men cong wen jian zhong du ru “1981”,$_ jiang bao han “1981n”。 zheng ze biao da shi zhong de ju dian pi pei “8” he “1”, er bu pi pei “n”。 zhe li zheng xu yao zhe yang zuo , yin wei huan xing fu bu shi ri qi de zu cheng bu fen 。
  dui yu yi ge bao han hen duo xing de chuan , wo men ye xu yao ti qu qi zhong de da de kuai , zhe xie kuai ke neng hui kua yue xing fen ge fu 。 zai zhe zhong qing kuang xia , wo men ke yi shi yong /s xuan xiang , bing yong ju dian lai pi pei chu le huan xing fu yi wai de suo you zi fu 。
  if (m{(.*?)}s) {
  print "Found bold text: $1n";
  }
  ci chu , wo yong le {} lai biao shi zheng ze biao da shi de qi shi he jie shu , er bu yong xie gang , suo yi , wo jiu ke yi gao su Perl wo zheng zai pi pei , qi shi zi fu wei "m", jie shu zi fu wei "s"。 ni ke yi ba /s he /m xuan xiang zu he shi yong :
  if (m{^(.*?)}sm) {
  # ...
  }
  zong jie
  you liang zhong fang fa da kai wen jian :open() han shu de te dian shi kuai su jian jie , er sysopen() han shu gong neng qiang da er fu duo 。 tong guo cao zuo fu , ke yi du ru yi ge ji lu ,$/ bian liang ke yi rang ni kong zhi ji lu shi shen me 。 ru guo ni da suan ba hen duo xing de nei rong du ru dao yi ge chuan zhong , bu yao shi yong wang ji /s he /m zhe liang ge zheng ze biao da shi biao ji 。
  【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
   du ru duo ge ji lu    ru guo ni tiao yong , fan hui wen jian zhong sheng yu de ji lu 。 ru guo ni chu yu wen jian yi , ze fan hui kong biao :   @records = ;   if (@records) {   print "There were ", scalar(@records), " records read.n";   }    zai xia mian de yi bu zhong , jin xing fu zhi he ce shi liang xiang gong zuo :   if (@records = ) {   print "There were ", scalar(@records), " records read.n";   }   chomp() ye ke shi yong dui shu zu cao zuo :   @records = ;   chomp(@records);    dui yu ren he biao da shi , dou ke yi jin xing chomp cao zuo , gu ni ke yi zai xia mian de yi bu zhong zhe yang xie :   chomp(@records = );    shen me shi ji lu ?    ji lu de que sheng ding yi wei :“ xing ”。    ji lu de ding yi you $/ bian liang kong zhi de , gai bian liang cun fang suo shu ru de ji lu de fen ge fu , yin wei huan xing fu zi fu ( gen ju ding yi !) shi yong lai fen ge xing de , gu qi que sheng zhi wei chuan “n”。    li ru , ni ke yi yong ren he ni xiang yao ti huan de fu hao lai dai ti “n”。   $/ = ";";   $record = ; # du ru xia yi ge yong fen hao fen ge de ji lu   $/ ke yi qu qi ta liang ge you qu de zhi : kong chuan ("") he undef。    du ru duan luo   $/ ="" de xie fa shi yong lai zhi shi Perl du ru duan luo de , duan luo shi you liang ge huo liang ge yi shang de huan xing fu gou cheng de wen ben kuai 。 zhe bu tong yu she zhi wei "nn", hou zhe jin du ru you liang xing zu cheng de wen ben kuai 。 zai zhe zhong qing kuang xia , jiang chu xian zhe yang yi ge wen ti : ru guo you lian xu de kong xing cun zai , li ru “textnnnn”, ni ji ke yi ba ta jie shi wei yi ge duan luo ("text"), ye ke yi jie shi wei liang ge duan luo ("text", hou mian gen liang ge huan xing fu , yi ji yi ge kong duan luo , hou mian gen liang ge kong xing 。)    zai du ru wen ben shi , di er ge jie shi yong tu bu da 。 ru guo ni zheng zai du de duan luo chu xian shang shu qing kuang , ni bu bi guo lv chu “ kong ” duan luo 。   $/ = "nn";   while () {   chomp;   next unless length; # tiao guo kong duan   # ...   }    ni ke yi ba $/ she zhi wei undef, ta yong yu du ru hou mian gen zhe liang ge huo duo ge huan xing fu zu cheng de duan luo : undef $/;   while () {   chomp;   # ...   }    du ru zheng ge wen jian   $/ de qi ta you qu de zhi wei undef。 ru guo she zhi wei gai zhi , jiu jiang gao su Perl, du ming ling jiang ba wen jian de sheng yu bu fen zuo wei yi ge chuan fan hui :   undef $/;   $file = ;    yin wei gai bian le $/ de zhi , jiang hui ying xiang yi hou de mei ci du cao zuo , er bu jin shi xia yi ge du cao zuo 。 tong chang , ni xu yao jiang gai cao zuo xian zhi zai ju bu 。 tong guo xia mian de li zi , ke yi ba wen jian ju bing de nei rong du ru dao yi ge chuan zhong :   {   local $/ = undef;   $file = ;   }    ji zhu :Perl bian liang ke du ru hen chang de chuan 。 jin guan ni de wen jian da xiao bu ke yi chao chu ni de xu ni nei cun rong liang de xian du , ni reng ke yi du ru jin ke neng duo de shu ju 。    yong zheng ze biao da shi dui wen jian jin xing cao zuo    yi dan ni you ge bao han le zheng ge chuan de bian liang , ni ke yi shi yong zheng ze biao da shi , dui zheng ge wen jian jin xing cao zuo , er bu shi dui wen jian zhong de mou ge kuai jin xing cao zuo 。 you liang ge you yong de zheng ze biao da shi biao ji /s he /m。 yi ban ,Perl de zheng ze biao da shi dui xing jin xing chu li , ni ke yi zhe yang xie :   undef $/;   $line = ;   if ($line =~ /(b.*grass)$/) {   print "found $1n";   }    ru guo ba wo men de wen jian tian ru ru xia nei rong :   browngrass   bluegrass    ze shu chu wei :   found bluegrass    ta mei you zhao dao “browngrass”, zhe shi yin wei $ jin zai chuan yi xun zhao qi pi pei , ( huo zhe zai chuan jie shu qian de yi xing )。 ru guo zai bao han hen duo xing de chuan zhong , yong "^" he "$" lai pi pei ,, wo men ke yi shi yong /m ("multiline") xuan xiang :   if ($line =~ /(b.*grass)$/m) {}    xian zai cheng xu hui ba ru xia de xin xi shu chu :   found browngrass    lei si di , ju dian ke yi pi pei chu le huan xing fu zhi wai de suo you zi fu :   while () {   if (/19(.*)$/) {   if ($1 < 20) {   $year = 2000+$1;   } else {   $year = 1900+$1;   }   }   }    ru guo wo men cong wen jian zhong du ru “1981”,$_ jiang bao han “1981n”。 zheng ze biao da shi zhong de ju dian pi pei “8” he “1”, er bu pi pei “n”。 zhe li zheng xu yao zhe yang zuo , yin wei huan xing fu bu shi ri qi de zu cheng bu fen 。    dui yu yi ge bao han hen duo xing de chuan , wo men ye xu yao ti qu qi zhong de da de kuai , zhe xie kuai ke neng hui kua yue xing fen ge fu 。 zai zhe zhong qing kuang xia , wo men ke yi shi yong /s xuan xiang , bing yong ju dian lai pi pei chu le huan xing fu yi wai de suo you zi fu 。   if (m{(.*?)}s) {   print "Found bold text: $1n";   }    ci chu , wo yong le {} lai biao shi zheng ze biao da shi de qi shi he jie shu , er bu yong xie gang , suo yi , wo jiu ke yi gao su Perl wo zheng zai pi pei , qi shi zi fu wei "m", jie shu zi fu wei "s"。 ni ke yi ba /s he /m xuan xiang zu he shi yong :   if (m{^(.*?)}sm) {   # ...   }    zong jie    you liang zhong fang fa da kai wen jian :open() han shu de te dian shi kuai su jian jie , er sysopen() han shu gong neng qiang da er fu duo 。 tong guo cao zuo fu , ke yi du ru yi ge ji lu ,$/ bian liang ke yi rang ni kong zhi ji lu shi shen me 。 ru guo ni da suan ba hen duo xing de nei rong du ru dao yi ge chuan zhong , bu yao shi yong wang ji /s he /m zhe liang ge zheng ze biao da shi biao ji 。   
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有