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

Hi all, Here's a question from a Perl beginner. If my program writes to itself (ie, data following __DATA__), can I package it as a Windows executable with PAR or another packer and still have it work? In other words, will Windows allow an executing file to be altered by such self-writing? Thanks in advance. cypress

Replies are listed 'Best First'.
Re: writing data to executable file
by dragonchild (Archbishop) on Nov 18, 2007 at 02:14 UTC
    DBM::Deep allows this and those tests pass on Win32 platforms. So, I would say that the answer is "Yes."

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: writing data to executable file
by holli (Abbot) on Nov 18, 2007 at 13:23 UTC
    Interestion question, but I'd say no. At least not as you think. PAR and other "pseudo compilers" simply pack all files needed to run the script into a single self extracting archive. When you run it, the files get unpacked into a temporary directory. So altering the script file might work as long as the temp directory exists. To be sure it always works, you'd have to manipulate the archive itself (which in the case of PAR is simply a ZIP file)!

    Anyway, I wonder why you want to store data in your script file. Why not just use an external file like (~/.yourapp, or MyFiles/.yourapp (for Windows))?


    holli, /regexed monk/
      Or use PAR::read_file
Re: writing data to executable file
by cypress (Beadle) on Nov 19, 2007 at 00:17 UTC
    Thanks for your replies. I hope to hear more before I delve in. To "holli," my reason for wanting to write to my executable is to keep my project as a single file (rather than have users extract a folder with multiple files and add still more files with data: I guess I just want it to "look" clean and simple). cypress

      Looking clean and simple may not be a good trade for being complicated with a nasty implementation - especially as "clean" in this case seems to be one file rather than two.


      Perl is environmentally friendly - it saves trees