Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Why can't some of my modules do log output to a file?

by Marshall (Canon)
on Oct 10, 2022 at 21:57 UTC ( [id://11147331]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Why can't some of my modules do log output to a file?
in thread Why can't some of my modules do log output to a file?

Instead of closing the file handle, you could just release the lock.  flock $fh, LOCK_UN or die "flock can't release lock $!";

Note from the docs: "To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE before locking or unlocking it."
So, lock, write, unlock will cause 2 flushes. There is no need to explicitly seek or flush.

Replies are listed 'Best First'.
Re^5: Why can't some of my modules do log output to a file?
by haukex (Archbishop) on Oct 11, 2022 at 06:20 UTC
    Instead of closing the file handle, you could just release the lock.

    That's what LanX and I both said.

    So, lock, write, unlock will cause 2 flushes.

    That's why I wrote "lock-seek-write-flush-unlock" and not "flock-seek-print-flock", because I was referring to the underlying operations.

    There is no need to explicitly seek

    That is very wrong unless you know for sure that O_APPEND semantics are guaranteed. For example, if the file was opened with '+<' instead of >> or on NFS filesystems, you definitely need the seek or you will corrupt your data.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11147331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-23 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found