- 论坛徽章:
- 95
|
本帖最后由 MMMIX 于 2015-12-07 21:55 编辑
回复 40# sunzhiguolu
#!/usr/bin/perl
use strict;
use warnings;
use v5.14;
use autodie;
use Data::Dumper;
use Tie::File;
if (@ARGV < 1) {
die "Usage: $0 file.txt";
}
tie my @arr, 'Tie::File', $ARGV[0], autodefer => 0;
(tied @arr)->defer();
for (@arr) {
$_ = '> ' . $_;
}
say "=== Before Flush ===";
system 'cat', $ARGV[0];
(tied @arr)->flush();
say "=== After Flush ===";
system 'cat', $ARGV[0];
Demo:
$ echo -e 'abc\ndef\nijk' > /tmp/d82.txt
$ cat /tmp/d82.txt
abc
def
ijk
$ ./p82.pl /tmp/d82.txt
=== Before Flush ===
abc
def
ijk
=== After Flush ===
> abc
> def
> ijk
|
评分
-
查看全部评分
|