Create a file

How do I generate a filename out of a variable?
That means create a filename like 'myname.dat' from an input of name=myname, and store data in it.


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.

 my $time = time();
  my $dir = "/home/joeuser";

  open FILE, ">>$Dir/$time.$$.txt";

$time is just that.. a time stamp
$$ is the proc id..
and I added the .txt ext, for the heck of it.. but you can make it anything you want..

then you simply write to FILE like normal and close FILE when youre done..

Good luck..
do not open with the >>, this is append mode, you asked how to create.

I think it is miuch simpler:

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
open(FILE,">$myname"); #would be one step simpler
# but >> also creates, if the file does not exist (or check $! if it fails)
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

doebuckAuthor Commented:
Help! it seems I'm having problem with
open (FILE, ">filename.txt");

It won't create a new file. and if i add the
open (FILE, ">filename.txt")
|| die "can't open temp for writing because $!"; i get internal error.

did i miss out some permission issues here?
Is the directory write protected?
Are you the owner of the directory?
Does a file already exist?
is the File handle FILE used elsewhere already?
Is the statement ABOVE the Open file one correct?

How are you calling the open?

Can you open ANY other file names?

What do you mean by "internal error"?
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

From novice to tech pro — start learning today.