At 9:04 PM +0000 11/15/99, Richard Smith wrote: >I'm almost embarrassed to ask this question, it seems so obvious: > >Is there a way to pass a text string from one CGI script to another? > >The CGI scripts I use at the moments use a common subroutine for displaying >errors such as illegal access, missing details, etc. The body of the script >passes a text message to the subroutine for inclusion in the HTML output. >Obviously, if I want to change the HTML, I have to change every script that >uses the routine. What I want to do is make the error reporting routine a >separate script, which receives the text from the active script and outputs >the HTML. > >I can do this locally, by having the main script generate a temporary text >file, then using a 'do' to run the error routine, which opens the same text >file and prints the contents. However, this is not an very good solution >online. Though the chances of two or more simultaneous users generating an >error are remote (my site doesn't get the traffic), 'in a curved universe, >all things are possible', and I would rather be safe than sorry. > >Does anyone have an ideas? I need to do the same thing, but I don't need to generate temporary files, so any number of users can do this simultaneously. My error-return mechanism comprises two files (not counting the main CGI script invoked by the browser): a perl script with a subroutine that takes a string error message, and an HTML template. All the CGI scripts "require" this perl script, and simply call the subroutine with the appropriate error message and then exit. I'm not on my main machine to copy/paste real scripts, but it would look something like this: --------- do_function.pl, invoked by browser via cgi --------- require "cgi-error.pl" # cgi code, blah blah blah . . . # test for problem if ( param_bad ) { cgi_error_return( "Your credit card is declined! Please choose another or stop spending so much money!" ); exit; } # continue with non-error html . . . --------- cgi-error.pl ------------ sub cgi_error_return() { #get the error parameter my ( $error_msg ) = @_; #open the error-template file if ( open( $EFILE, "error_template.html" ) ) { while (<>) { # substute error message for tag s/\<errortag\>/$error_msg/; #output the html line print $_; } } } --------- error_template.html --------- <HTML> <BODY> <errortag> </BODY> </HTML> ---------------------------------- HTH, Rudi ==== Want to unsubscribe from this list? ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org