Solved

Wanted-a complicated routine to name a file

Posted on 1997-08-01
3
171 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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 …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now