- 论坛徽章:
- 23
|
回复 #3 qiyanse 的帖子
可能我说的不准确,以代码为例吧:
- $ seq 10 > test.xml
- $ cat test.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- $ cat test.pl
- #! /usr/bin/perl
- use strict;
- use warnings;
- open FR,"<test.xml" or die "Cannot open test.xml:($!)\n";
- open FW,"+<test.xml" or die "Cannot open test.xml:($!)\n";
- while(<FR>)
- {
- print FW $_ if $. == 1;
- }
- truncate(FW,tell(FW));
- close FR;
- close FW;
- $ test.pl
- $ cat test.xml
- 1
复制代码
- $ seq 10 > test.xml
- $ cat test.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- $ cat test.pl
- #! /usr/bin/perl
- use strict;
- use warnings;
- open FR,"<test.xml" or die "Cannot open test.xml:($!)\n";
- open FW,"+<test.xml" or die "Cannot open test.xml:($!)\n";
- while(<FR>)
- {
- print FW $_ if $. == 1;
- }
- #truncate(FW,tell(FW));
- close FR;
- close FW;
- $ test.pl
- $ cat test.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
复制代码 |
|