Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Thread safe equivalent of LINUX touch command

by flexvault (Monsignor)
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005142]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-02-18 11:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (253 votes). Check out past polls.