SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old January 3rd, 2001, 01:44 PM
Kilokahn Kilokahn is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Lorain, OH, USA
Posts: 0 Kilokahn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Kilokahn
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

Reply With Quote
  #2  
Old January 3rd, 2001, 01:58 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > TXT/HTML Parsing Help Needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway