Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Wanted-a complicated routine to name a file

Posted on 1997-08-01
3
Medium Priority
?
187 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 400 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 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