|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
I was given a code by the kind Kent Boortz, but I am very confused with it. My original question was:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Including HTML into CGI then printing out the answers: I have a simple CGI that displays HTML (that is inside the code itself) with a string simular to: print <<EOF; <html><head><title>!name!: Configure Your Preferences</title></head> <center> EOF Well, editing this CGI for my HTML templates does not seem fruitful. I would rather have the CGI pull the HTML into it and then edit the fields (see !name! above) and print the completed part out. [/quote] Kent's reply with code was: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> I use templates for all my scripts. Like the example my %data = ( 'name' => 'kent' ); subst_write_template(%data, "/path/to/template"); where sub subst_write_template($) { my $query = shift; my $template = shift; open(TEMPLATE,$template) | | die "Can't open "$template": $!n"; while(<TEMPLATE> ) { s/${([A-Za-z][w-]*)}/$query->{$1}/g; s/$([A-Za-z][w-]*)/$query->{$1}/g; print; } close TEMPLATE; } and the template look like <html> . . . $name . </html> [/code] There are 2 problems. (1) I have NEVER seen a 'where' used before. (2) I cannot figure out how to put this into a Perl script. Can someone help me please? Thanks, Chris |
|
#2
|
||||
|
||||
|
I think the "where" is just a comment that wa not commented out in the code. If your using this code in your script, the routine: subst_write_template calls the sub to produce the template for display and the %data is passed to the template as an referenced hash.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> my %data = ( 'name' => 'kent' ); subst_write_template(%data, "/path/to/template"); # COMMENT => where sub subst_write_template($) { my $query = shift; my $template = shift; open(TEMPLATE,$template) | | die "Can't open "$template": $!n"; while(<TEMPLATE> ) { s/${([A-Za-z][w-]*)}/$query->{$1}/g; s/$([A-Za-z][w-]*)/$query->{$1}/g; print; } close TEMPLATE; } [/code] ------------------ <A HREF="http://www.thunder-rain.com" TARGET=_blank> Thunder Rain Internet Publishing</A> Providing Personal/Business Internet Solutions that work! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > TXT/HTML Parsing Help Needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|