文章摘要
这篇文章介绍了如何使用 Perl 语言对文件进行读写操作。文章首先展示了如何通过打开一个文件并写入内容到文件中,具体代码示例包括使用 `open` 和 `print` 函数进行文件操作。接着,文章详细讲解了如何从文件中读取内容,并通过读取结果进行处理。文章内容简明扼要,重点突出了文件操作的基本步骤和代码实现。
!/usr/bin/perl -w
use strict;
!/usr/bin/perl -w
use strict;
#print “please input a string\n”;
#my $line=<STDIN>;
#print $line;
#wirte a file
open(FH, “>aa.txt”) or die $!;
print FH “hello\n”;#向文件写入内容
print FH “OK\n”;
close(FH);
#open a file
open(FH, “aa.txt”) or die $!;
my @f=<FH>;#将文件内容读出
print @f;
close(FH);
© 版权声明
文章版权归作者所有,未经允许请勿转载。