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

Re: Thread safe equivalent of LINUX touch command

by flexvault (Parson)
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 drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-09-17 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls