Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Should i "use CGI" for a simple HTML file output?

Status
Not open for further replies.

wardy66

Programmer
Jun 18, 2002
102
AU
Hi all

Just a "style" question.

CGI is a standard module and appears to be a bit of an easy way to write HTML.

So, rather than:
Code:
print "<h1>Heading</h1>\n";

I can just:
Code:
print h1("Heading");[\code]

which seems a little less [i]low-level[/i].

Is this what people normally do? Please note, this script just outputs an HTML file, not a real CGI script.

I see there's also modules like HTML::Table that I might use too ...

Thanks! :)
 
Not sure if you were reffering to my post Trojan. I was sort of making an independent observation about allowing/denying access via names/password authentication and the common mistake of thinking the login screen is sufficient security.

But on the topic of the thread....

I think hard coding html is as portable (but is it as easy to maintain?) as letting CGI.pm generate it. I also think if a coder prefers hard coding the html into a script that is a personal choice that isn't really much on an issue as long as they have a good working knowledge of proper html code. There are advatanges to using CGI.pm, especially with form data and form generation. The ability to easily disable uploads is a great feature and the limitation on post data should always be taken advantage of in any CGI script.

I don't see that aspect of CGI.pm it as much of a portability issue, more of a maintanence issue. What are your thoughts?
 
If people had used CGI.pm to generate old-style HTML, it'd have been more portable to XHTML for a start ;-)
 
Sorry Kevin,
You're absolutely right, I screwed up there thinking you were Spyderco.
Apologies for that.

Great point by Ishnid though. When you centralise your interface with tools like CGI.pm then as the technology changes you don't have to do anything to your code. Simply upgrade the module and you're away.


Trojan.
 
hehehe.... ishnid is a sly one. That's seems like a generous definition of portability, html to xhtml. But I respectfully conceed that point to sir ishind. [wink]
 
If you want to use CGI.pm, that's fine. I would encourage it personally but depending on what your script does, you may not need to load it. If not, it's just needless overhead (even if it is a little bit).

I always use it because of the scripts I am working on.

Using CGI.pm with the objects and internal goodness the script can become more portable. That's one of the reasons CGI.pm has the hardcore "garbage" like

Code:
  print $q->blockquote(
                     "Many years ago on the island of",
                     $q->a({href=>"[URL unfurl="true"]http://crete.org/"},"Crete"),[/URL]
                     "there lived a Minotaur named",
                     $q->strong("Fred."),
                    ),
       $q->hr;

That is a lot of unecessary code but it will adhere to HTML standards, even if you don't. But it does make your scripts more portable.
 
I'm confused about this HTML issue, how do I use PERL to write my static, sHTML/HTML pages.

Completely static, no dynamic content, how would I use CGI.pm to generate this?

and what is XHTML

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
why would you want to use CGI.pm to print static html pages? But it's the same as writing html for pages with dynamic content.

Code:
use CGI;
my $q = new CGI;
print header,start_html,'Hello World',end_html;

but talk about over kill. You may as well use a flame thrower to light the bar-b-que. [wink]
 
my point is, i write my static HTML, which is acceptable, why does the same HTML code become unaceptable when perl is printing it to the screen?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
For the record, my remark above was more of a smart comment than a real indication of my practices.

I don't generate (X)HTML pages with CGI.pm (apart from tiny, trivial things). Neither do I use HERE docs or horrible double-quoted strings of (X)HTML with a zillion backslashes in them. As much as possible, I try to avoid mixing languages together. For that reason, I use external CSS stylesheets and external Javascript files (on the very rare occasion when I use Javascript these days) to keep them seperated from my (X)HTML. I use HTML::Template for almost all CGI-related stuff (apart from the truly trivial) so that I can seperate my Perl from my (X)HTML.

If it's a small script, I'll just throw my template into <DATA>. For bigger things, I'll use CGI::Application (which is *wonderful*) and use multiple templates. Either way, I never have (X)HTML directly embedded in the middle of my Perl code. It's a nightmare to maintain and it's extremely difficult to collaborate with any Perl-illiterate web designer. The number of times I've seen questions like "what's wrong with my code" and it's hard to tell which language in their javascript/perl/html/css mess is causing the problem is quite scary.

There's nothing *wrong* with mixing them, per se. It is mostly a matter of personal preference. That's what I think about it, though.
 
i'd love to know more on this CGI::Application thing isnid, if you use it it's gotta be a good thing.

I here what your saying about a zillion backslashes, and to the untrained eye it's a scary business.

Luckily i'm the only person who programs this stuff, for work and at home, so me being the only one who understands it, is A) not a big deal and B) could be beneficial at a later date ( Catch my drift ;-) ).

But as you know , if that really was my intention i wouldn't have just released version 4 of the members area implementing all the great new things you guys have taught me.

I want to improve and do my coding in the best way possible, but sometimes needs must and achieving your goal in the time frame, sometimes requires un-authordox practices, which is never the "Best" way to do it.

Again a persons knowledge/understanding of a language or environment can seriously influence the way they do things, you could ask "Why have you done it like that" and inevitably the answer will be "Because it's the only way i know how!".

I'd like to understand more on using a template approach and even from an Object Orientated angle, which fishi has nicely got the ball rolling with, but for now , time is such i don't have the time to study properly, even writing replies on Tek-Tips is sometimes using valuable time, it's just as well the knowledge and input you get out of tek-tips and this great community outweighs the few minutes a day i spend on here.

speaking of which must dash, got to implement the MS Access code the other forum has kindly helped with, you see PERL isn't the only thing i have to work with , although it has to be my favourite language i've used to date, if not just for the other nice people who use it like you guys.

speak later :)





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top