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

Perl 文件操作 (IO::File)

发布时间:2020-12-15 23:43:31 所属栏目:大数据 来源:网络整理
导读:# author : ez# date 2015/6/15# describe : append write a file#! perluse strict;use warnings;use IO::File; # import symbolsmy $fname = "./ko.pl";my $fd = undef;sub main () {$fd = new IO::File $fname,O_WRONLY | O_APPEND; # write only and app
# author : ez
# date 2015/6/15
# describe : append write a file
#! perl

use strict;
use warnings;
use IO::File; # import symbols

my $fname = "./ko.pl";
my $fd = undef;

sub main () {
	$fd = new IO::File $fname,O_WRONLY | O_APPEND; # write only and append
	print $fd "this sentends;n";  # write string into <$fd>
	$fd -> setpos ($fd -> getpos);
	undef $fd; # automatically close file handle
}

&main;

基本的读取:

sub rf () {
        # or this
        # my $fname = "> ./ko.pl"; then you can read without calling open ()
       ?my $fname = "./ko.pl";
	$fd = new IO::File; # call constructor
	$fd -> open ($fname);
	print <$fd>; # print all content of this file
	$fd -> close;
}

&rf;

(编辑:李大同)

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

    推荐文章
      热点阅读