this
is just
an example.
上記がout.txtであると仮定しましょう。out.txtを読み、同じファイルに書き込みたい。
<Hi >
<this>
<is just>
<an example.>
out.txtを変更しました。いくつかの行の最初と最後にタグを追加したいと思います。ファイルを数回読み取るため、毎回別のファイルに書き込み続けることはできません。
EDIT 1
使用してみ"+<"
ましたが、次のような出力が得られます。
Hi
this
is just
an example.
<Hi >
<this>
<is just>
<an example.>
**out.txt**
参照用の編集2 コード:
open(my $fh, "+<", "out.txt");# or die "cannot open < C:\Users\daanishs\workspace\CCoverage\out.txt: $!";
while(<$fh>)
{
$s1 = "<";
$s2 = $_;
$s3 = ">";
$str = $s1 . $s2 . $s3;
print $fh "$str";
}