Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Calling functions in middle of CGI HTML declarations

by sundialsvc4 (Abbot)
on Aug 27, 2012 at 00:56 UTC ( #989897=note: print w/replies, xml ) Need Help??

in reply to Calling functions in middle of CGI HTML declarations

Whereas I would chime in for Template::Toolkit, but the essential point is the same:   you should, insofar as possible, clearly separate program logic from presentation.   If When the marketing department says to you, “that looks great, but can you just ... (insert complete page makeover here),” you should be able to do that just by changing a template.   The program logic builds data structures (and provides functions), then the template iterates through them.   “Separation of concerns.”

Templating systems have considerable power for just this reason.   You can loop through data structures, make decisions, call Perl functions and so-on from within a template.   (Usually, the templating system works by building and compiling a Perl subroutine on-the-fly.)

Postscript:   This is one of the “lessons learned” of the PHP community ... and a hard lesson it was, because the intrinsic design of PHP is originally was very-specifically to allow logic to be embedded into the HTML.   Today, you won’t find any PHP pro doing that anymore (although plenty of legacy apps do and always will remain).   They all use templates now, and objects, and the language and its user-contributed-source libraries have grown in these directions.   While you may still find books that teach that approach, it is now widely recognized as a poor practice for the reasons aforesaid.

  • Comment on Re: Calling functions in middle of CGI HTML declarations

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989897]
[Discipulus]: good morning nuns and monks!
[marioroy]: Morning Discipulus. porting C code to Perl is an interesting problem for running parallel. I will try and the reason for attempting Perl code to match C 100%.
marto waves
[Discipulus]: hello marioroy! yes i need to start to write parallel, but not with this Pi code; it is yet melting my brain on it's own!

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-10-24 07:08 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (286 votes). Check out past polls.