summaryrefslogtreecommitdiffstats
path: root/lib/MDK/Common/File.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MDK/Common/File.pm')
-rw-r--r--lib/MDK/Common/File.pm10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/MDK/Common/File.pm b/lib/MDK/Common/File.pm
index a44c479..4dbb99d 100644
--- a/lib/MDK/Common/File.pm
+++ b/lib/MDK/Common/File.pm
@@ -342,11 +342,15 @@ sub substInFile(&@) {
fsync($F);
unlink "$file$^I"; # remove old backup now that we have closed new file
} else {
- local *F; my $old = select F; # that way eof return true
+ #- special handling for zero-sized or nonexistent files
+ #- because while (<>) will not do any iteration
+ open(my $F, "+> $file") or return;
+ #- "eof" without an argument uses the last file read
+ my $dummy = <$F>;
local $_ = '';
&$f($_);
- select $old;
- eval { output($file, $_) };
+ print $F $_;
+ fsync($F);
}
}