Re:[MacPerl-WebCGI] Page return alternative techniques
[email protected] Mon, 12 Mar 2001 21:21:22 +0900
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <v04011704b6d26b4e2892@[61.115.107.203]> |
"John Murray" <[email protected]> wrote >I want to do the usual password - username test and send a "success" or a >"fail" page back to the browser....alternatives that may enable changes >to the content of the fail and success pages without having to edit the >actual perl script. If you don't want embedded variables in the pages you want to use you can just read-in and print from an external file. If however you're looking to provide dynamic content you can still use an external text file but you'll need to add something like this to the CGI doing the reading in: #===TEMPLATE file (save this somewhere)==== Title: %%title%% blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah %%test%% blah blah blah blah blah blah blah blah blah blah blah blah blah blah #===TEMPLATE file (save this somewhere)==== ===Script====== #! perl -w use strict; use diagnostics-verbose; my($path)='path:to:file'; #change this to the path of the template file print template("$path", { 'title' => 'This is the title', 'test' => 'this is a test' }); sub template { my ($filename, $fillings); ($filename, $fillings) = @_; my $text; local $/; # slurp mode (undef) local *F; # create local filehandle open(F, "< $filename") || return; $text = <F>; # read whole file close(F); # ignore retval # replace quoted words with value in %$fillings hash $text =~ s{ %% ( .*? ) %% } { exists( $fillings->{$1} ) ? $fillings->{$1} : "" }gsex; return $text; } ===Script====== Or if this thecnique isn't sofisticated enough, look into the Text::Template module which (fortunately) is available in MacPerl flavour HTH Robin