我是 Perl 脚本的新手。
我想对文件进行读写操作。我将以读写模式(+<)打开一个文件,然后写入一个文件。现在,我想读取我之前写过的文件。下面是我的代码:
#!/usr/bin/perl
`touch file.txt`; #Create a file as opening the file in +< mode
open (OUTFILE, "+<file.txt") or die "Can't open file : $!";
print OUTFILE "Hello, welcome to File handling operations in perl\n"; #write into the file
$line = <OUTFILE>; #read from the file
print "$line\n"; #display the read contents.
当我显示读取的内容时,它显示一个空行。但是文件“file.txt”有数据
Hello, welcome to File handling operations in perl
为什么我无法阅读内容。我的代码是错误的还是我遗漏了什么。