Solved

Wanted-a complicated routine to name a file

Posted on 1997-08-01
3
177 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
importing users to Security group 2 50
Folder Permission Powershell 4 56
AWS CLI - Instances, Volumes & Tagging 2 92
Auto-indent certain lines in Notepad++ 10 73
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

808 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