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

Hi, I am trying to create a data.txt in C:\temp with the below code,however I dont see the file getting created,any idea what might be wrong?

open($CONFLICTS, '+>', "C:\\TEMP\\data.txt") or die $!; print $CONFLICTS "@data";

Replies are listed 'Best First'.
Re: Creating a file in temp folder
by ikegami (Patriarch) on Apr 13, 2011 at 19:10 UTC
    Either the file was created, or an error message was issued explaining why it wasn't.
Re: Creating a file in temp folder
by wind (Priest) on Apr 13, 2011 at 18:50 UTC

    Looks fine to me too, although I suspect you don't need '+>' mode, but just '>'. Read the following tutorial that covers modes for opening files: perlfile.

    Do you get any errors when calling open or print?

Re: Creating a file in temp folder
by eff_i_g (Curate) on Apr 13, 2011 at 20:03 UTC
    The others have asked the proper questions. I'm just here to suggest File::Temp.
Re: Creating a file in temp folder
by mikeraz (Friar) on Apr 13, 2011 at 18:41 UTC

    It works on my system. What other information can you provide?


    Be Appropriate && Follow Your Curiosity
Re: Creating a file in temp folder
by fidesachates (Monk) on Apr 13, 2011 at 20:31 UTC
    The previous monks' questions are good ones. Please take some time to answer them.

    My thoughts are that change the file name and the folder you're writing to. Temp is pretty common folder name and data.txt is also fairly common file name. It's conceivable that another process is interfering. Hence why I suggest trying to write to a different location with a different name. See if that changes it things. If it does, you know it has to do with your environment and you could do with some investigative work.

      or to get simple on it, make the file name Data.$$.txt and have the program print to STDERR "writing to Data.$$.txt" or some such message.

      $$ is the PID for the program, random enough in this case.


      Be Appropriate && Follow Your Curiosity
Re: Creating a file in temp folder
by twotone (Beadle) on Apr 14, 2011 at 01:41 UTC

    When I run into a problem with code that writes to a file, I like to test it writing into the same directory the perl is being run from to make sure it's not a file path issue. i.e.:

    open($CONFLICTS, '+>', "data.txt") or die $!; print $CONFLICTS "@data";

    Then it's easy to check in the same folder your perl code resides to see if it wrote the file.