bladx has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How do I CREATE a new text file in perl?

Replies are listed 'Best First'.
Re: How do I CREATE a new text file in perl?
by tadman (Prior) on Feb 17, 2001 at 01:52 UTC
    You can do that with the standard open() call and print:
    my ($file) = 'thefilename.txt'; open (FILE, ">$file") || die "Could not write to $file\n"; print FILE $stuff; close (FILE);
    The > in the open call means to open for writing. You can create it empty, too, by not writing anything.
      Thanks for the help!! I should have known open could do both things, thanks!
Re: How do I CREATE a new text file in perl?
by Albannach (Monsignor) on Feb 17, 2001 at 01:51 UTC
    Read a bit about open and you'll find that the output file is created if it doesn't exist.

    Update: In addition to tadman's advice you might also check out file test operators which come in handy when one is mucking about creating files.

    --
    I'd like to be able to assign to an luser