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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bespoke HTML, CSS, JavaScript with CGI 4

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I've been using PERL for many years and write all my HTML code by hand using a zillion backslashes.

On a few of my posts people have said "Why are you writing HTML, use the CGI module, you'll never have to write a line of HTML code again"

one claimed they write all theire CSS menu's, forms, webpages etc.. with the PERL CGI module.

can someone explain to me how, how can the CGI module know how to draw your menu, without you using HTML, this doesn't make any sense to me.

Can anyone help explain how all this is done with the CGI module without writing a single line of HTML?

Thanks 1DMF



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Cool - reading with excitement, though i would make a comment - this is on the first line.
It is not uncommon to see people call HTML a programming language

So I guess I must be common - lol

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I like the end bit that's funy
Write down a hundred times:
HTML is a data format, not a programming language.
You are allowed to use any programming language to write a loop that writes that text 100 times. You are also allowed to try to do that in HTML.

I guess you could use the link you gave to also apply to the diference between "Scripting" & "Programming".

True programming code is compiled, the other is interpreted, but where does that leave High Level Languages, such as VBA, I don't compile my code persae, is it compiled on the fly?, or is it interpreted.

The link does imply although you cannot say HTML is programing, you can class it as a "Computer Language" and say you are "Coding".

And beleive me, when my collegues see HTML on my screen, as i'm the only IT bod, as far as they are concerend it's computer gobbledygook and i'm "Programming".

lol - perspective is a funny old thing.

great link, that desreves a star!

:)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi

1DMF said:
I don't compile my code persae, is it compiled on the fly?
If you mean, compiled into stand-alone executable, unlikely. But a lot of interpreters compile the script into their own internal bytecode format, which is faster to execute. For example [tt]perl[/tt], [tt]gawk[/tt], [tt]bc[/tt]. ( Sorry, no idea where I read about them. )

Feherke.
 
lol - i think my brain hurts enough for one day anyway.

computer languages is like a kid in a sweet shop , so many to choose from, and not enough money (their case) and time (my case) to have them all.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Sorry for jumping into this late, but have you considered separating your presentation from the code completely? There are a few templating modules available for Perl (Template::Toolkit and HTML::Template to name two) that handle this exceptionally well. It also allows a person that is not familiar with Perl to update the pages and CSS as they see fit.

Just a thought.

- George
 
I'm very interested in changing my pages to templates, i've yet to find a way to do it, I thought this CGI might.

Are these modules standard or do i need to get them and include them?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
These would have to be added. I use HTML::Template quite regularly, as it's easy to use and has less problems cross-platform.
 
Guys,
Sorry for appearing late on this thread.
The main reason for abstracting your html generation as Kevin tried to point out is to allow a single simple change to completely map all of your code in one hit.
For example, say you are currently producing HTML 4.01 standard and all of a sudden you want to produce XHTML or anything else for that matter that conforms to the basic structure of the HTML we all know and love.
In principle, you change one flag somewhere and all your code magically changes and produces XHTML instead of HTML.
Your "<br>" suddenly becomes "<br />" in all places that it's output and you have not had to change more than a single line of code to get that effect.
I am not suggesting that CGI.pm is the saviour for all your problems, merely trying to offer the explanation for why you might consider using it.


Trojan.
 
I think that was Paul that tried to point that out Trojan. [wink]
 
im still unclear what is the best option is it CGI or Template module.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Template is great for separating the html from the processing.
Generally a very good idea but it may not give the same abstraction that CGI.pm gives (if used that way).
I guess you need to decide if you need that abstraction either from the language (eg HTML) or you need the code vs markup separation that a template system gives, or indeed if you don't need either!
Maybe if you try to imagine updating the system in, say, 6 months, are you likely to have to re-write sections, and if so, why? Will you be kicking yourself for having 100's of files with 1000's of pieces of markup that need a minor change?



Trojan.
 
so if it aint broke , don't fix it ? is that what ya saying

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The answer is: without seeing your entire script it's not possible to give more than a generic answer. If it's a big complicated script converting even to just using CGI.pm could take more time and energy than it's worth. Converting to a templating system could be even harder.

If you ever write another script from scratch then start using CGI.pm at least to get the form data if not to print HTML, which I don't care for myself but does have the advantage of making it a simple case of updating the CGI.pm module to update all your HTML/XML code in the entire script. Thats also the time to look into using templates.
 
Is there a bit of chain yanking going on??

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Is there a bit of chain yanking going on??
huh? , what's chain yanking.

anyway, I think your right Kevin, though I have re-written my scipts, er i think i'm on version 5.

It has taken time to edit all my scripts just to apply a new design and layout.

i have a major rewrite on a members side of things i haven't started yet, i was concidering adoptind beter practices and getting it "Right" this time (for a change).

I've been banging my head in many of tek-tips forums (and annoying the odd person - what's new!), trying to grasp the overall concept of what language/method I should use for what. I think i've got the concept down now, please correct me if i'm wrong.

PERL (my chosen language) is for processing & content.
HTML/XHTML is for structure.
CSS is for layout/formating.

although you can mix the three, i.e have PERL output the HTML (hard coded) or even use the style attribute for inline formating within HTML tags, both are concidered bad practices.

you should keep the three separate, thus i should use PERL to process and create the dynamic content, then use HTML to structure what is to be outputed (this is done vis CGI or Template) and use a CSS style sheet for layout and formating.

i'm still a bit confused as to why the TABLE tag is such a bad word, but have found CSS does not bode well if your HTML is structured via a bunch of nested tables, it's also hard to break old habits when at the time of learning HTML, tables were the only easy method of geting things layed out and centered correctly.

again i'm still unsure why if Frames / iFrames are so bad the tag exists in the first place, but we won't go there today.

I do take on board what the HTML/CSS forum has pointed out, that until I get my HTML "Valid", it will be hard to truely incorporate the power of some features available via CSS or other methods (i.e. Javascript)

This is no different than when I came to you guys for the first time with my PERL and didn't know what 'use srtict', meant or did, let alone use it :) , but thans to the extremly nice bods here in the PERL forum, who showed patience, understanding, and a real willing to help me improve, have taught me so much, I now have PERL code, that although, is not perfect, (mainly due to a zillion backslashes and hardcoded HTML), at least it is valid and decently written PERL.

(i wish the other forums were as tolerant and understanding as this one, I guess different languages suit different people, and the PERL bods, seem to be a nice bunch, though don't get me wrong, there are some extremley helpfull, pleasant and talented bods in the other forums also)

the problem I have is because my skills have been self taught using a fusion of all the languages/methods, I don't fully understand each of them in their own right, as the saying say "Jack of all trades, master of none!".

which can be very handy in getting things done, quickly, and to a time scale, but that often doesn't mean properly!

and yes that can lead to not being the quickest way in the end anyway, if you're forever chasing down bugs, which you can't find because the way everything has been thrown together.

I'm proud of what i've achieved so far and for some of my sites i've even adopted the ajax method but like most things i do, it's "bolted on", so most definately is not the correct or best usage of this great tool.

i know it will be painfull and I have a long task ahead, but i feel i need to rip my site apart, and re-build from the ground up.

I think the starting point is from my PERL point of view, get my scripts back to being "Just PERL",no hardcoded javascript and HTML all over the shop, if I pull this out of my PERL then I need someway to "Merge" the dynamic content to my (what tecnically is now) static HTML, I guess the only way to do this is via some type of template system.

that way I will also be able to ensure my HTML/XHTML is correctly structured along with my CSS and be in a position to validate it. (unless the HTML layout is such for a template that the #DATA# identifiers in the HTML won't validate through w3c).

how would you go about this, where should i go to understand this template module, and please don't send me to somewhere like CPAN, it's not wittern in english to me!

I need to understand how I create an external template, PERL as the backend, how to layout current pages, in correct HTML, without 100's of nested tables, the ability to dynamically add what Javascript file should be used in the head, css file to be used etc.

Or am i trying to make my code too perfect, when all that matters is "does it work", "Does it do the job" , "does it really need changing".

applying a new layout or "Skin" is the main reason I have, it's a nighmare having to edit loads of hardcoded html in the PERL scripts everytime I change my layout or colour scheme.

anyway I think i've rambled enough, as always I look forward to any replies.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The theme for your site should be completely controlled (as near as is possible) with one or more external CSS files.
Do not embed CSS source in your perl or HTML, just a link to the file(s). This allows any changes to the theme in the CSS to reflect across the whole site instantly.
The same applies to any JavaScript. Try to keep as much code as possible in an external file and link to it. Your HTML/perl should only ever call functions from that external code. That way, again, any changes reflect in the entire site instantly with only one change in the .js file.


Trojan.
 
yup that's what i was coming to the conclusion of, it doesn't help when the way you learn many things is at these script sites, with instructions just paste this into your head, and this in the body and this here and that there etc...

which can also be said for the style attribute in HTML tags (inline) or even putting the style tag in the head of the HTML.

i want to break this way of doing things, the part i'm stuck with is the PERL part, how i merge dynamic content with external HTML templates.

any pointers?

I think the CSS bit for layout is going to be difficuly as well, i'm sure i read somewhere stating when CSS took hold the move from straight HTML to CSS will be a dificult transition / learning curve for even the hardiest of HTML coders, but well worth the rewards once achieved.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
with instructions just paste this into your head, and this in the body and this here and that there etc...
You have to bear in mind that on sites like Tek-Tips, it's easier to express an answer using inline styles (or maybe <style> elements) because its keeps everything in one piece of code. It's a succinct way of saying "apply this bit of CSS to this bit of HTML". In actual practice - when you have multiple HTML pages to style - it's nearly always better to use an external stylesheet.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top