Thanks, That's a good idea :) I just cannot figure out the zero bytes bug... I've managed to stump quite a few people with it, by the way. But I think it has something to do with sysopen and truncate but I can't be sure.
Update:
I totally recoded the old sysopen part but I'm not sure if what I did will work...
sub safe_open {
my $fn = shift;
my $fh = do { local *FH };
my ($mode, $result);
if ($fn =~ /^>[^>]/) {
$mode = 1;
}
elsif ($fn =~ /^>>/) {
$mode = 2;
}
else {
$mode = 0;
}
if ($mode == 1 and $flock_enabled) {
# Write mode with flock.
$truncate_please = 1;
my $fhtemp = do { local *FHT };
$result = open( $fhtemp, "+>>$fn" );
if ($result) {
$result = open($filehandle, ">&$fhtemp" );
close($fhtemp);
}
}
elsif ($mode == 1) {
# Write mode without flock.
$result = open($fh, ">$fn");
}
elsif ($mode == 2) {
# Append mode.
$result = open($fh, ">>$fn");
}
elsif ($mode == 0) {
$result = open($fh, $fn);
}
unless ($result) {
# Open failed.
fatal_error("Couldn't open $fn.");
}
flock($fh, 2) if $flock_enabled;
if ($truncate_please) {
truncate($fh, 0) or fatal_error("Could not truncate file $fn."
+);
}
return $fh;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.