如何在文件中将行插入Perl中文件的开头?

Wil*_*iam 2 perl

我使用Perl帮助器对此进行编码.它看起来我错过了一个角色或什么的.我需要将新文本写入文本文件的顶部.

open (LOGFILE, ">> complete.txt") ; # writes new to the bottom

$datetime = localtime ;

print LOGFILE "\n" ;

print LOGFILE $datetime\n" ;
print LOGFILE "$name\n" ;
print LOGFILE "Has completed the work\n" ;

close (LOGFILE) ;
Run Code Online (Sandbox Code Playgroud)

Dav*_*oss 8

这在Perl FAQ中得到了解答.

如何更改,删除或插入文件中的行,或附加到文件的开头?

如果您使用Perl进行编程,那么值得花一个小时左右来浏览常见问题解答.它充满了有用的信息.