Hi, the CGI is designed to take data from a post request (which works fine), and then use that data to upload an image to a separate directory, and edit an html which will display that image and information (this is basically an inventory update script). The file upload seems to work perfectly, and the HTML part of this CGI works great and shows the uploaded image and all the data just fine, but the gallery.html file remains the same, as if the CGI file is either not trying to edit the file, or cannot. The script is also designed to get the Total Inventory count from a comment in the gallery.html file, but I dont know if that is working because the rest isn't working.

This may be more of a permissions problem than a Perl problem, but I've even tried chmodding the gallery.html to 777 temporarily to see if that resolved the issue (which it didn't). Any advice on what I may be doing wrong and why the script isn't writing to the html file would be greatly appreciated. Thanks!

rather then updateing the html file its self why not use a database rather it being a CSV (flat file) or SQL (Sqlite) CSV is the easist to todo. Then you can generate your gallery.html from whats in the database file.

Unfortunately, coding knowledge is extremely weak, and the SQL and template options, while I'm sure are more effective and efficient, look like greek to me :/ I've been able to fix all the random bugs in the code and get it to work -except- for the very last section of writing the html to the gallery.html file. The earlier opening and looking for the Inventory Item number works perfect, but apparently when it writes to the file at the end, something messes up and I end up with a 0 byte file.

The idea being that I open the file, and read it line by line, and change out any lines matching the old inventory end line with the new inventory item block. hence the While <FILE>, $_ =~ s/olditemend/olditemend+newblock/g;

I realize that there are much better ways to do what I'm trying to do, but this is literally the last step of the whole project, and once I figure it out I can sleep :/ I feel like if I do one of the other suggestions, It'd take me hours to understand why I'm changing things and to change them correctly.

You're opening the file in write mode, which clobbers any data that it may have had.

Code

while (<FILE>) {

Here you're attempting to read from the file you just opened in write mode. That's not going to do anything useful.

You need to reverse those steps. Open the file in read mode and apply one or more regex's as you parse the data and place it into a data structure.

Once that parsing/updating is done, open the file in write mode and output the saved data from the data structure.

There are several variations of this type of approach, none of which I recommend.

Learning how to use a template will take less time than debugging the messy approach that you're currently attempting. All you need to do is make a few minor adjustments to your existing html file to turn it into a template and then in your script you'd make a few simple var assignments instead of the manual parsing that you're currently attempting.