Below my sig. is a couple of example scripts that show you what I'm talking
about.

The first script (query.cgi) displays an empty form, stores the submitted
query to a unique(*) file and tells the browser to refresh its contents with
the result script.

(*) Please note that I have used time() as the unique identifier - this is
ok for prototyping but you should really use a better unique number
generator and/or check that a query file (*.in) with the chosen identifier
does not already exists in the watched directory.

The results script (result.cgi) checks if the result file has arrived (this
has the same basename as the input file but has the extension of .out
instead of .in).  If the file does exists it displays the results as a
bullet list, otherwise it displays a "result pending" message.

You can test this by calling the fist script then enter a dummy query, watch
it refresh a few times then rename the "*.in" file to "*.out".  The next
time the result page refreshes you should see your original query text in
the bullet list.

Now all you need to do is write a daemon that watches a specified directory
for *.in files and processes them, creating *.out files containing the
results.

Ps. I test my CGI scripts under Apache/Win32.  If you're running IIS you'll
probably get errors saying it's "too late" for the -T (taint) switch.
Either edit your IIS mappings to specify the -T there (or just delete the
shebang line altogether).

--
  Simon Oliver

#!perl -T
# query.cgi -- [EMAIL PROTECTED], 2002-04-18
use warnings;
use strict;
use CGI qw(fatalsToBrowser);

my $q = new CGI;
my $query = $q->param('query');

if (length($query) < 1) {

# display the query form

 print $q->header, $q->start_html(-title => 'Query Form');
 print $q->start_form,
  $q->textfield(-name => 'query'),
  $q->submit(-value => ' go '),
  $q->end_form;
 print $q->end_html;

} else {

# display the query subitted page

 my $unique = time();
 my $file = "c:/temp/$unique.in";

 open FH, ">$file"
   or die "Error opening query file '$file' for write: $!\n";
 print FH $query;
 close FH;

 print $q->header;
 print $q->start_html(
  -title => 'Query Submitted',
  -head => $q->meta({
   -http_equiv => 'Refresh',
   -content => "5; URL=/cgi-bin/result.cgi?id=$unique"
  })
 );
 print $q->p([
   "Your query has been submitted and assigned the id of '$unique'. ",
   "Your browser should periodically update this page and display
    the query results when they become available. ",
   "If your browser does not automatically refresh this page click
    <A HREF=\"/cgi-bin/result.cgi?id=$unique\">here</A>
    to display the query results. "
 ]);
 print $q->end_html;

}


#!perl -T
# result.cgi -- [EMAIL PROTECTED], 2002-04-18
use warnings;
use strict;
use CGI qw(fatalsToBrowser);

my $q = new CGI;
my $unique = $q->param('id');

my $file = "c:/temp/$unique.out";

if (-e $file) {

# display the results page

 open FH, "<$file"
   or die "Error opening result file '$file' for read: $!\n";
 my @results = <FH>;
 close FH;
 print $q->header, $q->start_html(-title=>'Query Results');
 print $q->p("Here are the results for query: id=$unique.");
 print $q->menu($q->li(\@results));
 print $q->end_html;

} else {

# display the results pending page

 print $q->header;
 print $q->start_html(
  -title => 'Query Results Pending',
  -head => $q->meta({
   -http_equiv => 'Refresh',
   -content => "5; URL=/cgi-bin/result.cgi?id=$unique"
  })
 );
 print $q->p([
   "Your query has been submitted and assigned the id of '$unique'. ",
   "Your browser should periodically update this page and display
    the query results when they become available. ",
   "If your browser does not automatically refresh this page click
    <A HREF=\"/cgi-bin/result.cgi?id=$unique\">here</A>
    to display the query results. "
 ]);
 print $q->end_html;

}


_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to