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

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

2008-05-19 06:25:51 编辑來源:互联网 评论
 
 
 
本文为【适合初学者的Perl的文件操作(1)】的拼音翻译版
  wei le geng hao de kong zhi wen jian de da kai fang shi , ke yi shi yong sysopen() han shu :
  use Fcntl;
  sysopen(FH, $filename, O_RDWR|O_CREAT, 0666)
  or die "Can't open $filename for reading/writing/creating : $!";
  han shu sysopen() dai you si ge shen shu , di yi ge shi tong open() han shu lei si de wen jian ju bing shen shu , di er ge shen shu shi bu dai mo shi xin xi de wen jian ming , di san ge shen shu shi mo shi shen shu , you Fcntl mo kuai ti gong de luo ji OR yun suan zu he qi lai de chang shu gou cheng , di si ge shen shu ( ke xuan ), wei ba jin zhi shu xing zhi (0666 biao shi shu ju wen jian , 0777 biao shi cheng xu )。 ru guo wen jian ke yi bei da kai ,sysopen() fan hui true, ru guo da kai shi bai , ze fan hui false。
  bu tong yu open() han shu ,sysopen() bu ti gong mo shi shuo ming de jian xie fang shi , er shi ba yi xie chang shu zu he qi lai , er qie , mei ge mo shi chang shu you wei yi de han yi , zhi you tong guo luo ji OR yun suan cai neng jiang ta men zu he qi lai , ni ke yi she zhi duo ge xing wei de zu he 。
  O_RDONLYRead-only
  O_WRONLY Write-only
  O_RDWR Reading and writing
  O_APPEND Writes go to the end of the file
  O_TRUNC Truncate the file if it existed
  O_CREAT Create the file if it didn't exist
  O_EXCLError if the file already existed (used with O_CREAT)
  dang ni xu yao xiao xin xing shi de shi hou , jiu shi yong sysopen() han shu , li ru , ru guo ni da suan tian jia nei rong dao wen jian zhong , ru guo wen jian bu cun zai , bu chuang jian xin wen jian , ni ke yi zhe yang xie :
  sysopen(LOG, "/var/log/myprog.log", O_APPEND, 0666)
  or die "Can't open /var/log/myprog.log for appending: $!";
  du ru dan ge ji lu
  you yi ge rong yi de fang fa du ru filehandles: yong cao zuo fu 。 zai biao liang nei rong xia , ta fan hui wen jian zhong de xia yi ge ji lu , huo zhe fan hui wei ding yi chu cuo xin xi 。 wo men ke yi shi yong ta lai ba yi xing du ru dao yi ge bian liang zhong :
  $line = ;
  die "Unexpected end-of-file" unless defined $line;
  zai xun huan yu ju zhong , wo men ke yi zhe yang xie :
  while (defined ($record = )) { # long-winded
  # $record is set to each record in the file, one at a time
  }
  yin wei yao da liang jin xing zhe yang de gong zuo , tong chang zai jin xing yi xia jian hua ,
  ba ji lu fang dao $_ zhong , er bu shi $record zhong :
  while () {
  # $_ mei ci wei wen jian zhong de yi ge ji lu
  }
  zai Perl 5.004_04 zhong , wo men ke yi zhe yang zuo :
  while ($record = ) {
  # $record mei ci wei wen jian zhong de yi ge ji lu
  }
  defined() jiang zi dong jia shang , zai Perl 5.004_04 yi qian de ban ben zhong , gai ming ling gei chu yi ge jing shi 。 yao le jie suo yong de Perl ban ben , ke zai ming ling xing xia da ru :
  perl -v
  yi dan wo men du chu le yi ge ji lu , tong chang da suan qu diao ji lu fen ge fu ,( que sheng zhi wei huan xing fu zi fu ):
  chomp($record);
  Perl 4.0 ban ben jin you chop() cao zuo , qu diao chuan de zui hou yi ge zi fu , bu guan gai zi fu shi shen me 。chomp() mei you zhe me da de po huai xing , ru guo you xing fen ge fu cun zai , ta jin qu diao xing fen ge fu 。 ru guo ni da suan qu diao xing fen ge fu , jiu yong chomp() lai dai ti chop()。
  【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
   wei le geng hao de kong zhi wen jian de da kai fang shi , ke yi shi yong sysopen() han shu :   use Fcntl;   sysopen(FH, $filename, O_RDWR|O_CREAT, 0666)   or die "Can't open $filename for reading/writing/creating : $!";    han shu sysopen() dai you si ge shen shu , di yi ge shi tong open() han shu lei si de wen jian ju bing shen shu , di er ge shen shu shi bu dai mo shi xin xi de wen jian ming , di san ge shen shu shi mo shi shen shu , you Fcntl mo kuai ti gong de luo ji OR yun suan zu he qi lai de chang shu gou cheng , di si ge shen shu ( ke xuan ), wei ba jin zhi shu xing zhi (0666 biao shi shu ju wen jian , 0777 biao shi cheng xu )。 ru guo wen jian ke yi bei da kai ,sysopen() fan hui true, ru guo da kai shi bai , ze fan hui false。    bu tong yu open() han shu ,sysopen() bu ti gong mo shi shuo ming de jian xie fang shi , er shi ba yi xie chang shu zu he qi lai , er qie , mei ge mo shi chang shu you wei yi de han yi , zhi you tong guo luo ji OR yun suan cai neng jiang ta men zu he qi lai , ni ke yi she zhi duo ge xing wei de zu he 。   O_RDONLYRead-only   O_WRONLY Write-only   O_RDWR Reading and writing   O_APPEND Writes go to the end of the file   O_TRUNC Truncate the file if it existed   O_CREAT Create the file if it didn't exist   O_EXCLError if the file already existed (used with O_CREAT)    dang ni xu yao xiao xin xing shi de shi hou , jiu shi yong sysopen() han shu , li ru , ru guo ni da suan tian jia nei rong dao wen jian zhong , ru guo wen jian bu cun zai , bu chuang jian xin wen jian , ni ke yi zhe yang xie :   sysopen(LOG, "/var/log/myprog.log", O_APPEND, 0666)   or die "Can't open /var/log/myprog.log for appending: $!";    du ru dan ge ji lu    you yi ge rong yi de fang fa du ru filehandles: yong cao zuo fu 。 zai biao liang nei rong xia , ta fan hui wen jian zhong de xia yi ge ji lu , huo zhe fan hui wei ding yi chu cuo xin xi 。 wo men ke yi shi yong ta lai ba yi xing du ru dao yi ge bian liang zhong :   $line = ;   die "Unexpected end-of-file" unless defined $line;    zai xun huan yu ju zhong , wo men ke yi zhe yang xie :   while (defined ($record = )) { # long-winded   # $record is set to each record in the file, one at a time   }    yin wei yao da liang jin xing zhe yang de gong zuo , tong chang zai jin xing yi xia jian hua ,    ba ji lu fang dao $_ zhong , er bu shi $record zhong :   while () {   # $_ mei ci wei wen jian zhong de yi ge ji lu   }    zai Perl 5.004_04 zhong , wo men ke yi zhe yang zuo :   while ($record = ) {   # $record mei ci wei wen jian zhong de yi ge ji lu   }   defined() jiang zi dong jia shang , zai Perl 5.004_04 yi qian de ban ben zhong , gai ming ling gei chu yi ge jing shi 。 yao le jie suo yong de Perl ban ben , ke zai ming ling xing xia da ru :   perl -v    yi dan wo men du chu le yi ge ji lu , tong chang da suan qu diao ji lu fen ge fu ,( que sheng zhi wei huan xing fu zi fu ):   chomp($record);   Perl 4.0 ban ben jin you chop() cao zuo , qu diao chuan de zui hou yi ge zi fu , bu guan gai zi fu shi shen me 。chomp() mei you zhe me da de po huai xing , ru guo you xing fen ge fu cun zai , ta jin qu diao xing fen ge fu 。 ru guo ni da suan qu diao xing fen ge fu , jiu yong chomp() lai dai ti chop()。   
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有