Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Thread safe equivalent of LINUX touch command

by flexvault (Prior)
on Nov 22, 2012 at 14:59 UTC ( #1005142=note: print w/ replies, xml ) Need Help??

in reply to Thread safe equivalent of LINUX touch command

ISAI student,

I have a common module that includes the following:

sub Touch { my $file = shift; open ( my $TOUCH,">>",$file ) || Die_Rtn( 23, "$Caller: ! open fail +ure on |$file|"); close $TOUCH; }

In your code you call it the same way as you do now. Make sure you have the ">>" or you'll clear the file. Note: On some older *nix systems, I've had to actually do I/O to the file. In that case, I'd 'print' a "\n" to the end before closing. I didn't like that solution, but it did work and didn't cause any *KNOWN* problems.

I have used mostly 'fork', so I've never tried this with Threads, so others may suggest an alternative, but this works and is faster than calling the system 'touch'. 'Die_Rtn' is also in the common module and determines if the failure is for the user or the system and acts accordingly.

Hope this helps!

"Well done is better than well said." - Benjamin Franklin

Comment on Re: Thread safe equivalent of LINUX touch command
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-11-27 22:35 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (734 votes), past polls