http://qs1969.pair.com?node_id=54157


in reply to Re: CGI Benchmarks
in thread CGI Benchmarks

That is actually the current way that I am doing it, except for the fact that i have "data files" that hold the html.
ie.
open(HTML,"index.da1"); while(<HTML>){print $_;} close(HTML);
then I'll have whatever dbi stuff I have to do then do the same thing for "index.da2" and so on. Do you think that's slower than just having all the html code "embedded" into the perl?

Replies are listed 'Best First'.
(jeffa) 3Re: CGI Benchmarks
by jeffa (Bishop) on Jan 25, 2001 at 22:22 UTC
    Sorry I am a bit late on this thread.

    Without seeing the whole context of your example, I am prone to say that you are delving into serious overkill. Why use a Perl script to deliver the contents of a text file without doing anything to it? HTTP is perfectly capable of doing this for you. :)

    open(HTML,"index.da1"); while(<HTML>){ # do something to $_ print $_; } close(HTML);

    Yes, that is slower than embedding the code, because you have to open a file, as well as print each line. But, if you are actually doing something to each line, or even just a few special lines - then it is a viable solution. Of course, if you are just testing the waters, then that is certainly understandable.

    But that's not my point - database access will make your speed concerns with your current program seem very trivial.

    Which brings me to my real point - "embedding" HTML into a Perl script really only has one major issue in my books - MAINTAINABILITY!!

    If you are the only user of this script, don't worry about it. But, if you are coding for the good of a larger project, one that has HTML content writers and programmers - then you will want to seperate the HTML from the Perl.

    Generally, Perl programmers don't want to have to concern themselves with the details of HTML layout - and HTML writers usually can't understand Perl code.

    My first real assignment after graduating was a Cold Fusion project. My HTML was embedded in the Cold Fusion files like a cancer - and when it came time to tweak the position of this or that graphic, guess who had to do it? Me!! If I was smart, I would have seperated the HTML code completely, so that the HTML writers could tweak without having to be scared that they would screw everything up.

    If you really want to put your HTML code in separate files, look into HTML::Template, it is well worth your time.

    Jeff

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
      First off, I am the only person working on this script and chances are no-one else will ever maintain it other than me, so I can pretty much do whatever I want

      Here's an example of what I am doing:
      ... print "welcome ",$username, "your email address is ",$email; open(HTML,"index.da1"); while(<HTML>){print$_;} close(HTML); print "your manager is ",$manager; open(HTML,"index.da2"); while(<HTML>{print$_;} close(HTML);
      basically I print out some information from the database, then a whole wack of html code (index.da1) and then print out some more info from the database then a whole wack more of html (index.da2).

      obviously this is a very small example compared to what I am actually doing, but the basic idea is there.
      do you think it would be quicker just to have all the html 'embedded' into the perl? even though this would make the script well over 7500 lines long? Does that make a difference (file length)?

      skeight