Re: Template techniques [ newbie alert + long ]

2000-06-10 Thread Ged Haywood

Hi there,

On Thu, 8 Jun 2000, Perrin Harkins wrote:

 use references for passing data.

But see "Advanced Perl Programming" pages 9 (Performance Efficiency)
and 44 (Using Typeglob Aliases).

73,
Ged.






Re: Template techniques [ newbie alert + long ]

2000-06-08 Thread Perrin Harkins

On Thu, 8 Jun 2000, Greg Cope wrote:
 My original question was not related to templates (I'll use embperl for
 that)

Well, I'm confused now.  You'll use Embperl for templates but you're not
using Embperl for templates?

 - the area I was trying to explore was how to read a template (all
 HTML with a few !--TAGS-- in it) and the sub in the new content.

Embperl would work fine for that, but it's overkill.  Your substitution
approach is slower than compiling to perl subs, especially since you have
to load the file, but saves lots of memory and is fine for something as
simple as this.
 
 Has anyone any suggestions as to speeding this up - yet keeping it
 simple - I have played with referances to avoid all the variable copying
 etc . ?

Caching templates in memory would certainly help, but you'll eat up a
chunk of RAM.

- Perrin




Re: Template techniques [ newbie alert + long ]

2000-06-08 Thread Greg Cope

Perrin Harkins wrote:
 
 On Thu, 8 Jun 2000, Greg Cope wrote:
  My original question was not related to templates (I'll use embperl for
  that)
 
 Well, I'm confused now.  You'll use Embperl for templates but you're not
 using Embperl for templates?

I use Embperl when I want a templating system - but not when using HTML
templates (wrong use of names on my part) - I am refering to a template
in this case as an HTML file with a few special tags.

 
  - the area I was trying to explore was how to read a template (all
  HTML with a few !--TAGS-- in it) and the sub in the new content.
 
 Embperl would work fine for that, but it's overkill.  Your substitution
 approach is slower than compiling to perl subs, especially since you have
 to load the file, but saves lots of memory and is fine for something as
 simple as this.

Can you enlighten me into the compiling to perl subs ?

The file gets loaded once into shared memory - most (stripped) HTML
files are only a few 10's of K.

Also the file gets loaded once at startup - not during the request
stage.

  Has anyone any suggestions as to speeding this up - yet keeping it
  simple - I have played with referances to avoid all the variable copying
  etc . ?
 
 Caching templates in memory would certainly help, but you'll eat up a
 chunk of RAM.

If the html is usually reasonable in size, and the code I CP'ed strips
the template into one long strip with spaces / tabs (designers making
things all indented etc ..) at each end of the string - and chomp.

Also the templates are modular - in that one template covers main part
of the page, and other templates cover the rest.  This helps contiunity
in HTML design etc .. (i.e only make one changen in one place)


Thanks for the input.

Greg

 
 - Perrin



Re: Template techniques [ newbie alert + long ]

2000-06-08 Thread Perrin Harkins

On Thu, 8 Jun 2000, Greg Cope wrote:
   - the area I was trying to explore was how to read a template (all
   HTML with a few !--TAGS-- in it) and the sub in the new content.
  
  Embperl would work fine for that, but it's overkill.  Your substitution
  approach is slower than compiling to perl subs, especially since you have
  to load the file, but saves lots of memory and is fine for something as
  simple as this.
 
 Can you enlighten me into the compiling to perl subs ?

It's what Matt was talking about.  Your program parses the template,
generates perl code that produces the correct output, evals the code, and
stores the results in a sub reference which you can call whenever you want
that template.

The first time I ever saw this done was with ePerl, but I don't know if
that was really the first.  All the embedded perl systems popular around
here (Embperl, Apache::ASP, Mason, etc.) use some variation on this
technique.  I think the world's record for most compact implementation
goes to Randal for a small post you can find in the archive here:
http:[EMAIL PROTECTED]

 The file gets loaded once into shared memory - most (stripped) HTML
 files are only a few 10's of K.
 
 Also the file gets loaded once at startup - not during the request
 stage.

You probably won't get much faster than that then, no matter what you do.  
Just make sure your regexps are fast (maybe use "study"?) and use
references for passing data.

- Perrin




Re: Template techniques [ newbie alert + long ]

2000-06-08 Thread Randal L. Schwartz

 "Perrin" == Perrin Harkins [EMAIL PROTECTED] writes:

Perrin I think the world's record for most compact implementation
Perrin goes to Randal for a small post you can find in the archive here:
Perrin 
http:[EMAIL PROTECTED]

Ahh yes, Apache::Cachet (it's a cache, eh?), mostly proof of concept,
aborted when I started using HTML::Mason in a serious way.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!