open FILE with unique Name

I need to open a temp file to drop data into and need to make sure I don't run into a conflict if the same file is already open. What I need is some how check if the file exists and if so, give it a unique name. I then delete them after I have written/read to them, so they don't exists very long. I just need to make sure my script don't try and write to my temp file that may already be open under another process!

 
LVL 2
BiffoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cadabraCommented:
Hi,

If I understand your meaning, you have a perl script which needs to:

1. Create a temporary file
2. Write / Read data to/from temp file
3. Deletes the temporary file

If this is the case, consider something like:

$tmpfilename = "tmp$$.txt";

which creates a filename with the current process id embedded in it. This will be unique, as no 2 processes running concurrently on the system will have the same PID.

If I misunderstood your meaning, please reject the answer and explain further.

Cadabra.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BiffoAuthor Commented:
Well the code makes my temp file OK, but I having a tough time deleting it when I am done!!

0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

BiffoAuthor Commented:
oooooops here is your points since your answer is doing what I want!! Thank You.


0
cadabraCommented:
What kind trouble are you having deleting the file ?
0
cadabraCommented:
What kind trouble are you having deleting the file ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.