作者cutecpu (可爱中央处理器)
看板perl
标题Re: [请益] 文字档案中插入新文字.....
时间Wed May 31 17:09:45 2006
#!/usr/bin/perl
open FILE,"test.txt";
$s=<FILE>."ABCABC\n";
$s.=$_ while(<FILE>);
close FILE;
open FILE,">test.txt";
print FILE $s;
close FILE;
※ 引述《jacklinxp (开始工作)》之铭言:
: 有一个文字档假设内容为
: AAAAAA
: DFDFDSF
: BSDFDSF
: BSDFSD
: 如果我要在AAAAAA
: 後面新增文字的话,要如何去开档或者写入呢?
: 因为如果我用
: open FILE, ">> text.txt";
: 并在程式中使用print FILE, "ABCABC\n"
: 结果会是
: AAAAAA
: DFDFDSF
: BSDFDSF
: BSDFSD
: ABCABC
: 而不是我想要的
: AAAAAA
: ABCABC
: DFDFDSF
: BSDFDSF
: BSDFSD
: 请问要如何达到我想要的结果呢?有特别的function可以使用吗?
: 多谢大家的帮忙
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.63.246.28