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

Brother monks here gathered, I understand the written Perl required, but please tell me where my data files should be placed. My CGI is in the cgi-bin directory. All permissions are setup. Where do I put the data files such that they can be written to, and read by the CGI? open (MYFILE, ">>/usr/???/???/text.txt"); print MYFILE "where do I place my data file text.txt\n"; close (MYFILE); OK brothers show me the light, and the error of my ways. Thanks.

Replies are listed 'Best First'.
Re: CGI reading and writing to data files
by derby (Abbot) on Jun 11, 2007 at 13:00 UTC

    Well that depends on the underlying filesystem and what user you're running the webserver as. For me (linux ext3, nobody), /tmp does in a pinch but be careful - some systems clean out /tmp on a periodic basis. For long term storage I normally need to work with the system admins to set up a directory that the user nobody has write permissions and has enough disk space to meet my reqs.

    -derby
      For *nix operating systems the Filesystem Hierarchy Standard provides widely accepted guidelines to help you select the right directory for where to store files.
      /tmp is considered volatile so once you close a file it can be removed by the system, e.g. upon reboot
      /var/tmp is less volatile, you are supposed to remove any temporary files yourselves whenever you feel they are not needed anymore.
Re: CGI reading and writing to data files
by telcontar (Beadle) on Jun 11, 2007 at 16:53 UTC
    What the previous posters said :-)

    If whatever data you are storing is somewhat related to the system, or performing a system service (for instance, you are providing some sort of administrative web interface, reporting tool(s), etc), on *nix I would say it should be stored in /var/lib/<name> - that is, if you are the admin of the machine.

    HTH, telcontar