I think what he means is that if you do and open like +> you get RW access BUT you have stomped on the original file (if it existed). +>> is OK as is +<
my $file = 'foo.txt'; one(); two(); two(); one(); sub one { open my $fh, "+>", $file or die $!; print $fh "Hello World!\n"; seek $fh, 0, 0; print while <$fh>; close $fh; print "--\n\n"; } sub two { open my $fh, "+>>", $file or die $!; print $fh "japh!\n"; seek $fh, 0, 0; print while <$fh>; close $fh; print "--\n\n"; } __DATA__ Hello World! -- Hello World! japh! -- Hello World! japh! japh! -- Hello World! --
In reply to Re^2: read and write to the same file
by tachyon
in thread read and write to the same file
by dee00zee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |