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

perl 读写文件

发布时间:2020-12-15 23:56:07 所属栏目:大数据 来源:网络整理
导读:读文件 use strict;use warnings;sub open_display_file{ # the filename should be passed in as a parameter my $filename = shift; # open file to the handle FILE open(FILE,$filename) || die "Could not read from $filename,program halting."; # re

读文件

use strict;
use warnings;

sub open_display_file
{
  # the filename should be passed in as a parameter
  my $filename = shift;
  # open file to the handle <FILE>
  open(FILE,$filename) || die "Could not read from $filename,program halting.";
  
  # read the first line,and chomp off the newline
  #chomp(my $firstline = <FILE>);
  
  my $firstline = <FILE>;
  
  print $firstline;
  # read other into array
  my @other = <FILE>;
  print @other;
  close FILE;  
}

# a test to show how to call my function
&open_display_file('C:UsersenqrrsbDesktopNewfolderNew foldertest.txt');

写文件

use strict;
use warnings;
sub open_write_file
{
  # the filename should be passed in as a parameter
  my $filename = $_[0];
  # open file to the handle <FILE>
  open(FILE,">>",$filename) || die "Could not write to $filename,program halting.";
  
  print $filename."n";

  print FILE ($_[1]."n");
  # read other into array

  close FILE;  
}
 &open_write_file('C:UsersenqrrsbDesktopNewfoldertest.txt',"rrsb");

(编辑:李大同)

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

    推荐文章
      热点阅读