Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2015-07-04 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls