in reply to Re: Empty File Contnts before writing
in thread Empty File Contnts before writing
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Empty File Contents before writing
by gautamparimoo (Beadle) on Feb 19, 2013 at 09:47 UTC | |
by johngg (Canon) on Feb 19, 2013 at 10:04 UTC | |
by RichardK (Parson) on Feb 19, 2013 at 11:41 UTC | |
by johngg (Canon) on Feb 19, 2013 at 14:37 UTC | |
|
Re^3: Empty File Contents before writing
by locked_user sundialsvc4 (Abbot) on Feb 19, 2013 at 13:56 UTC | |
by gautamparimoo (Beadle) on Feb 20, 2013 at 05:43 UTC | |
by johngg (Canon) on Feb 20, 2013 at 23:17 UTC |