Gossamer Forum
Home : General : Perl Programming :

Writing Data from a feedback form to a database file

Quote Reply
Writing Data from a feedback form to a database file
Hi,

I found a script that writes the data from a feedback form to a text database. The only problem I am having w/ it is when I am importing the information in Excel it is listed in rows and not columns.
this is how it prints it to the text file now.
Quote:
e.g name : John
address: 124 harry st.
comments: help

This is how I want it to be in the text file so that when I import it in Excel it can be listed in columns.
Quote:
e.g Name Address Comments
John 1234 harry st. help

this is the sub routine that prints the data to that text file. I hope someone w/ some perl experience can help me out on this one.

Quote:
sub write_form_info {
open (FORM, ">>$form_info_path") | | die ("I am sorry, but I was unable to
open the file $form_info_path");
foreach $sortedkeys (@sortedkeys) {
$sortedkeys =~ s/^\d*\)\s*//;
$sortedkeys =~ s/required-//;
($name, $answer) = split (/\|/, $sortedkeys);
print FORM "$name -- $answer\n";
}

Thanks in advance
Quote Reply
Re: Writing Data from a feedback form to a database file In reply to
This should work, but I haven't tried it.

Instead of

print FORM "$name -- $answer\n";
}

try

print FORM "$answer\t";
}
print FORM "\n";

That will give you the unlabeled information on one line, with a tab between each element. It won't give you the column labels, though.

If you want the column labels, you'll have to go through the loop twice:

Code:
foreach $sortedkeys (@sortedkeys) {
$sortedkeys =~ s/^\d*\)\s*//;
$sortedkeys =~ s/required-//;
($name, $answer) = split (/\|/, $sortedkeys);
print FORM "$name\t";
}
print FORM "\n";
foreach $sortedkeys (@sortedkeys) {
$sortedkeys =~ s/^\d*\)\s*//;
$sortedkeys =~ s/required-//;
($name, $answer) = split (/\|/, $sortedkeys);
print FORM "$answer\t";
}
print FORM "\n";

You will end up with an extra tab at the end of the line, but that shouldn't be a problem.


------------------
JPD





Quote Reply
Re: Writing Data from a feedback form to a database file In reply to
thanks it worked like a charm