Yes, seek works in this case because the final output is longer than the initial output. But a word of caution is in order. Consider:
#! perl use strict; use warnings; my $filename = 'test.txt'; open(my $fh, '>', $filename) or die "Cannot open file '$filename' for +writing: $!"; print $fh "The quick brown fox jumped over the unfortunate dog."; seek $fh, 0, 0; print $fh "The final output."; close($fh) or die "Cannot close file '$filename': $!";
This results in file “test.txt” containing:
The final output.ox jumped over the unfortunate dog.
as seeking to the beginning of the file does not erase its existing contents.
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^2: Empty File Contents before writing
by Athanasius
in thread Empty File Contnts before writing
by gautamparimoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |