Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl / cgi / include file a la #include

Reply
Thread Tools

Perl / cgi / include file a la #include

 
 
ccc31807
Guest
Posts: n/a
 
      03-26-2010
On Mar 26, 5:53*pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> a better style i teach is called "print rarely, print late". instead of
> printing directly, return the string you make up.


In Paul Graham's book 'On Lisp' in chapter 3, 'Functional
Programming', he makes an extended case for this, which I find
compelling but not necessarily persuasive. I've been slowly making my
way through the dead tree version of HOP by MJD, and I also have found
a lot to like in that. My problems are (as Graham notes) an imperative
habit, a lack of opportunity, and little discretionary time.

> build up the final
> page in a buffer (using .= is easiest) and then you can decide what to
> do with it.


I actually use this quite a bit in my day job. I almost always find
myself constructing and deconstruction strings and arrays (and
hashes), moving between them, and as a result I do this quite a bit.
(I've also found the ||= operator useful.)

> you can print to stdout as usual, print to a file for later
> use by the web server, print to a socket if desired. or more than one of
> those at the same time. by printing directly from the html subs you lose
> the flexibility. it is also a bit faster to call print one time than
> multiple times (.= is faster than print). and you can decide where to
> print at the higher level which keeps the logic cleaner.


As an explanation if not a defense of what I wrote previously, most of
my HTML consists of front ends to databases, and most of the heavy
lifting is the SQL part. When I write my HTML files, I use variables
to trigger both the SQL and the HTML. I quite frequently end up with a
cgi script that looks something like this (illustration only):

HTML:rint_header(@vars1);
HTML:rint_banner(@vars2);
HTML:rint_menu(@vars3);
my $hashref = SQL::get_list($var1);
HTML:rint_content($hashref);
$hashref = SQL::get_calendar($var2);
HTML:rint_content($hashref);
HTML:rint_footer();
exit;

> i have seen
> requests for dual handles which can print to a file and to stdout (i
> think IO::Tee does that) but this is even easier and faster. so the rule
> print rarely means build up a full string in a buffer before you print
> it. print late means print only when you are done and can decide where
> to print it.


In this case, I am 'printing' a response to an HTTP request, not a
physical device. I also do some JSP, and for some reason, the JSP
doesn't seem any faster than my CGI, and sometimes is noticeably
slower.

CC
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
ASP Include file error <!-- #include file="" --> naveeddil ASP .Net 0 01-04-2008 12:58 PM
include file in include file PTM HTML 1 11-12-2007 10:13 AM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
#include "file" -vs- #include <file> Victor Bazarov C++ 4 03-06-2005 07:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57