Forum Moderators: coopster & phranque

Message Too Old, No Replies

Creating a file

How to?

         

adni18

1:21 am on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can perl create a file that doesn't exist yet?

upside

5:16 am on Oct 2, 2004 (gmt 0)

10+ Year Member



You could find the answer to your question in any introductory book to Perl but here it is:


open(LOG,">/path/to/file");
print LOG "hello world\n";
close(LOG);

adni18

1:48 pm on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So even if the file doesn't exist, it will create it?

mack

2:24 pm on Oct 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



that should create it but make sure you have the correct permissions set on the directory where the file will be created.

Mack.

volatilegx

8:47 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't it be...

open(LOG,"+>/path/to/file");
print LOG "hello world\n";
close(LOG);

note the "+" sign.