Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: PERL and HTML

by jonadab (Parson)
on Apr 19, 2006 at 12:24 UTC ( [id://544340]=note: print w/replies, xml ) Need Help??


in reply to PERL and HTML

Do not use DreamWeaver. Do not use DreamWeaver. That way might seem easier, but down that path you will find pain and suffering, because the HTML that you get out of DreamWeaver will be very hard to break into manageable pieces and integrate with the logic in your Perl script.

You can teach yourself enough HTML to get this done in about an hour using information that is available on the web. This is not very much more time than it would take to learn DreamWeaver, and the resulting HTML will be *MUCH* easier to work with and to integrate into your Perl code. HTML is very easy to learn, and will take much less time and effort than you spent learning Perl, to say nothing of Java or C++. An intelligent person with a natural bent toward computers can master HTML in a long weekend, and you don't need to master it; you just need to learn the basics.

Yes, CGI is the way to go for this. You will use a form element in your HTML, which will contain the various inputs, including a submit button. The action attribute of the form element will point to your Perl script. There are various CGI-related modules on the CPAN (see search.cpan.org), which you can use to get the form input. Some of them (for instance, CGI.pm) have complex interfaces for things like generating HTML, but you can safely ignore all of that. The only thing you need them for is to collect the form input. For generating the HTML, it's much easier to just learn HTML and use print statements (maybe with heredocs and/or the qq[somestring] quoting mechanism, since the strings you are printing will often contain quotation marks).

As far as sending the results back to the browser, the most important thing to know is that you have to print out the HTTP headers first, then a blank line, then whatever HTML you want to send. The only HTTP header that is mandatory is the Content-type header, which will look probably like this: Content-type: text/html\n

Enjoy this assignment. You've waited to the last second, but nonetheless writing CGI scripts is one of the easier and more pleasant programming assignments you could be given. Once you've written one of them, it becomes easy to whip together another one real quick sometime later. Before you know it you'll be doing your layouts with stylesheets, scripting events with Javascript, manipulating page elements via the DOM, and loading in parts of pages dynamically with XMLHttpRequest. But for now, just do the basic CGI script.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://544340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-16 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found