#!perl
use strict;
use warnings;
use 5.014;
my $filename=$ARGV[0];
open FILE1,"<$filename" or die "Can't open '$filename':$!";
open FILE2,"+<$filename" or die "Can't open '$filename':$!";
my $lines = join '',<FILE1>;
$lines =~ s/^/$filename:/gm;
print FILE2 "$lines";
close FILE1;
close FILE2;
简要说一下原理:F1和F2将使用不用的文件指针,F1的指针一定大于等于F2的指针,F2为可读写方式打开,可以对其进行修改