Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Values between programs without opening a file

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
US
I have written the following program to create a file, and them pass the values to another program. However, the second program does not recognize the values and gives errors. Is it possible to pass values between program without query and files?

Program I with values:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print &quot;<HTML><TITLE>LocalTime</TITLE>\n&quot;;
print &quot;<BODY BGCOLOR=\&quot;white\&quot;><center>&quot;;
print &quot;</center></BODY></HTML>&quot;;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
%FORM = ();
foreach $pair (@pairs) {
$pair =~ s/\+/ /g;
($name, $value) = split(/=/, $pair);
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;c&quot;, hex($1))/eg;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;c&quot;, hex($1))/eg;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's
$FORM{$name} = $value;
}
foreach $key (&quot;amount&quot;,&quot;phone&quot;)
{
print &quot;$key = $FORM{$key}<br>\n&quot;;
}
open(OUTF,&quot;>>test1.out&quot;) or dienice(&quot;Couldn't open survey.out for writing: $!&quot;);
flock(OUTF,2);
seek(OUTF,0,2);
print OUTF &quot;$FORM{'amount'}|&quot;;
print OUTF &quot;$FORM{'phone'}|&quot;;
close(OUTF);
print &quot; <br><a href=\&quot; Please click this </h3> </a>\n&quot;;
print <<EndHTML;
EndHTML
sub dienice {
my($msg) = @_;
print &quot;<h2>Error</h2>\n&quot;;
print $msg;
exit;
}

Program II to receive these values and assign them to another variable and ask for more:

#!/usr/bin/perl
print&quot;<html><head><title>testc1</title></head>\n&quot;;
print&quot;<body>\n&quot;;
print &quot;<form method=\&quot;post\&quot; action=\&quot;
$phone2=$phone;
$v =$amount;

print&quot;<input type=\&quot;hidden\&quot; name=\&quot;AMOUNT\&quot; value=\&quot;$v\&quot;>\n&quot;;
print&quot;<input type=\&quot;hidden\&quot; name=\&quot;TYPE\&quot; value=\&quot;A\&quot;>\n&quot;;
print&quot;<table>\n&quot;;
print&quot; <tr><td align=\&quot;right\&quot;>Telephone Number:<input type=\&quot;text\&quot; name=\&quot;phone\&quot; value=\&quot;$phone2\&quot; size =\&quot;30\&quot;><br></td></tr>\n&quot;;
print&quot; <tr><td align=\&quot;right\&quot;><input type=\&quot;submit\&quot; value=\&quot;click here to submit\&quot;></td></tr>\n&quot;;
print&quot;</table></form></body></html>\n&quot;;
 
The way you've written your programs, #1 is closed before #2 is started, therefoe any variable or array values are lost when #1 closes. Try making #2 a subroutine of #1 and call it after it's core processing is finished.

There's always a better way. The fun is trying to find it!
 
Thanks, it makes sense. If it works, I will let you know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top