Solved

Wanted-a complicated routine to name a file

Posted on 1997-08-01
3
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

626 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