+ -
当前位置:首页 → 问答吧 → 无法打开文件?

无法打开文件?

时间:2011-07-21

来源:互联网

先上代码:
  1. #1.Choose the input and output file
  2. print "please input the keyword1 you wanna chop off(the line contained the keyword would be deleted!)";
  3. $Keyword1 = <STDIN>;
  4. chomp $Keyword1;
  5. print "please input the keyword2 you wanna chop off(the line contained the keyword would be deleted!)";
  6. $Keyword2 = <STDIN>;
  7. chomp $Keyword2;
  8. print "please type in the document you wanna read in: \n";
  9. $documentinput = <STDIN>;
  10. chomp $documentinput;
  11. unless(open(FH,'$documentinput') ){
  12.         print "cant open input file $documentinput";
  13.         exit;
  14. }
  15. print "please type in the document you wanna write in: \n";
  16. $documentoutput = <STDIN>;
  17. chomp $documentoutput;
  18. unless(open(FH2,">$documentoutput")){
  19.         print "cant find output file $documentoutput";
  20.         exit;
  21. }

  22. #2.Take out every line of the txt document to $Content in order and check if key word is in $Content
  23. while($Content=<FH>){
  24.         if($Content =~ /$Keyword1/){
  25.                 print FH2 ''}
  26.         elsif($Content =~ /$Keyword2/){
  27.                 print FH2 ''}
  28.         else{print FH2 $Content}
  29. }
  30. close FH;
  31. close FH2;
  32. print "Mission Complete! please close this window and chech the write-in document.";
  33. sleep
复制代码
前两个keyword输入无问题,在进行$documentinput录入时输入D:/test.txt并回车后提示:
cant open input file D:/test.txt

test.txt确定存在

谢谢大家!

作者: shinra13   发布时间: 2011-07-21

自己搞定,多了一对引号。
这帖子咋删啊。。

作者: shinra13   发布时间: 2011-07-21



QUOTE:
先上代码:前两个keyword输入无问题,在进行$documentinput录入时输入D:/test.txt并回车后提示:
cant ope ...
shinra13 发表于 2011-07-21 01:06



要命的错误....   
unless(open(FH,'$documentinput') ){

作者: jason680   发布时间: 2011-07-21

热门下载

更多