Solved

Wanted-a complicated routine to name a file

Posted on 1997-08-01
3
179 Views
Last Modified: 2013-12-25
I have a series of scripts (see SCRIPT #1 and SCRIPT #2 below). Each respondent to a survey will complete the forms in a number of scripts (maybe 100 short forms with 3 to 10 questions each). A unique respondent ID ($rid) is generated in a script prior to these two and will have a value of something like 21655-870487819. This respondent ID is carried through to each form a particular user completes in a hidden field (see line 23 in SCRIPT #1 and line 27 in SCRIPT #2). I currently have the results being saved to a file named the respondent ID ($rid) (see lines 14, 15 & 16 in SCRIPT # 2) and this file is appended to with each form submitted. I have discovered that this raw data in one long file is not easy to process. So, I want to have each form saved as an individual file that is named the respondent ID ($rid) plus the name of the form_name value (see hidden field in line 25 in SCRIPT # 1 and line 29 in SCRIPT #2).

In other words, If the respondent ID is 21655-870487819, I want the data from the input of form one, to be saved in the file created in lines 14-16 of SCRIPT #2, and I want that file to be named 21655-870487819-demog ( this “demog” comes from the hidden field value in line  25 of SCRIPT #1). The next file saved in this series would then be named 21655-870487819-fam_hx

Clear as mud ???

Ask me questions if you need to, but I’ve tried to explain it as clearly as I can.

Can anyone come up with a routine that will do this ?

I am very inexperienced so please keep your answers as basic as possible.

Thanks in advance,
Morrie

***** For the purposes of this explanation, SCRIPT #1 (demog.cgi):

#! /usr/bin/perl

read(STDIN, $message, $ENV{'CONTENT_LENGTH'});

@pairs=split(/&/, $message);
foreach $pair (@pairs) {
($name,$value)=split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c",hex($1))/eg;
$FORM{$name} = $value;
}
$rid=$FORM{"respondent_id"};

print "Content-type: text/html\n\n";

print <<end;
<HTML><HEAD><TITLE>Demographics</TITLE></HEAD>
<BODY background="whitebak.gif" bgcolor="#ffffff"
text="#000080" link="#0064ff" vlink="#00a800" alink="#800000">

<FORM ACTION="fam_hx.cgi" METHOD=POST>

<INPUT TYPE="hidden" NAME="respondent_id" VALUE="$rid">

<INPUT TYPE="hidden" NAME="form_name" VALUE="demog">

<h2>Section I. Demographic Information:</h2>

[*MORE HTML DELETED*]

<INPUT TYPE="submit" VALUE="Go to the next section">
<INPUT TYPE="reset" VALUE="Reset/Re-enter data">
</FORM>
</body>
</html>
end


***** For the purposes of this explanation, SCRIPT #2 (fam_hx.cgi):

#! /usr/bin/perl

read(STDIN, $message, $ENV{'CONTENT_LENGTH'});

@pairs=split(/&/, $message);
foreach $pair (@pairs) {
($name,$value)=split(/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c",hex($1))/eg;
$FORM{$name} = $value;
}
$rid=$FORM{"respondent_id"};

open(LOGFILE, ">survey_results/$rid,form_name") || die "Can't open logfile!\n";
print LOGFILE "$message\n";
close (LOGFILE);

print "Content-type: text/html\n\n";

print <<end;
<HTML><HEAD><TITLE>Family History</TITLE></HEAD>
<BODY background="whitebak.gif" bgcolor="#ffffff"
text="#000080" link="#0064ff" vlink="#00a800" alink="#800000">

<FORM ACTION="dx1.cgi" METHOD=POST>

<INPUT TYPE="hidden" NAME="respondent_id" VALUE="$rid">

<INPUT TYPE="hidden" NAME="form_name" VALUE="fam_hx">

<h2>Section II. Family Medical History</h2>

[*MORE HTML DELETED*]

<INPUT TYPE="submit" VALUE="Go to the next section">
<INPUT TYPE="reset" VALUE="Reset/Re-enter data">
</FORM>
</body>
</html>
end
0
Comment
Question by:morrie
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
wormzer earned 100 total points
ID: 1829522
Try changing this line

   open(LOGFILE, ">survey_results/$rid,form_name")

to something like this:

   open(LOGFILE, ">survey_results/$rid$form_name")

That would name the file like you want.  You can put any variable you like inbetween quote marks and it'll put itself in the string.  Let me know if that does it...
0
 

Author Comment

by:morrie
ID: 1829523
It didn't work. The file was still named just the respondent id number ($rid). I think somewhere I need to create the variable $form_name. I know this sounds very simple, but I don't know how to do that. In line 12 of both scripts ther is the line:
$rid=$FORM{"respondent_id"};
I think this line creates the variable $rid. It seems like I need some similar line of code in every script to create the variable $form_name ???

Never mind!
Right in the middle of writing this I tried adding the line:
$form_name=$FORM{“form_name”}
and it worked. So in trying to explain the problem to you I figured out the answer. Thanks though, I couldn’t have done it without you.

I now hve a file named:
27526-870534213demog

Thanks,
Morrie

0
 
LVL 1

Expert Comment

by:wormzer
ID: 1829524
Great... I was just going to suggest you do what you did.  Sorry, I didn't see that you hadn't done that already.  Good luck with the rest of your scripts.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
excel file 5 76
Need to Modify a Script I found 5 108
How to create a textarea which saves text in HTML 8 47
AWK: Am I duplicating the comma delimiter in this code? 5 25
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question