* Dr. Internet columnist Steve Blass offers advice on how to save Web survey data to a file
endif; ?>An old survey form submitted through a Perl script called FormMail sends the survey data to an administrator in e-mail, and we want to store the data to a file instead. How can we do that in Perl?
FormMail can be modified to save submitted data to a comma-separated value (CSV) file, in addition to sending e-mail, by adding a few reasonably simple commands to the script.
First, get a copy of the FormMail.pl script to work with. If you don’t have access to the copy on your server, you can download it from Matt’s Script Archive (https://www.scriptarchive.com/formmail.html).
Open the script in a text editor and look for the “send_mail” subroutine by searching for “sub send_mail”. Four or five lines below that, you will see
open(MAIL,"|$mailprog");
add the line
open(CSV,">>mydata.csv");
immediately below that.
Search for the line
close(MAIL);
and add a line that says
close(CSV);
immediately below it.
Then for every line in the send_mail subroutine that begins with “print MAIL …”, create a duplicate immediately below it with “MAIL” replaced by “CSV.” FormMail will append the submitted data to the CSV file, and send an e-mail when a survey form is received.




