cat -E test1.txt
出力削除/追加上書き:Perlのファイルハンドル - データを既存の代わりに
car$
$
$
を私は「自転車」と「車」に変更し、新しい/空行を削除します。
これは期待通りに動作している:/
しかし、上記の場合には、私は、2倍の開口部を使用しています:
#!/usr/bin/perl -w
open(FILE1,"<","./test1.txt"); @araj=<FILE1>; close(FILE1);
open(FILE2,">","./test1.txt");
map {
[email protected]@[email protected]; [email protected]^\[email protected]@;
} @araj;
print(FILE2 @araj);
close(FILE2);
と
cat -E test1.txt
出力は私のために、100%正確ですファイルを閉じます。 私は2xファイルハンドルを使用しています。
1xファイルハンドル
(これは学習目的で、単に+> + >>どのように動作しているか理解しようとしています...)のみ使用します。たとえば
:
#!/usr/bin/perl -w
open(FILE2,"+<","./test1.txt"); #what file handle should be here? +> , +>> >> .... ?
@araj=<FILE2>;
map {
[email protected]@[email protected]; [email protected]^\[email protected]@;
} @araj;
print(FILE2 @araj);
close(FILE2);
出力が正しくありません。
car$
$
$
bike$
なぜこれが追加、ない上書きされますか?他のファイルハンドルを使用すると、結果も間違っています。例えば、空のファイル... 読み書きのために使用されるファイルハンドルはどれですか?
https://perldoc.perl.org/functions/seek.html –
@ikegami感謝して、ファイルサイズを変更します。修正されました。 – collector1871