vashbrowns has asked for the wisdom of the Perl Monks concerning the following question:
Hello to all.
I'm a new perl user (fresh UNIX class started in Spring), and my final project is due in a couple of weeks. I'm sorry to bother y'all with what is most likely simple questions, but I just don't know what to do because of my lack of experience.
The project asks us to create a time table for the New York subway system so that a user can identify his best choice of travel. The user will log onto an HTML page that I create, choose his starting location and ending location. Once this is done, my HTML page is supposed to send his selected information to my perl program for processing.
My perl program is supposed to figure out what his cheapest OR fastest choice of travel is, then send it back to the HTML page so the user can see where he is supposed to get on, get off, get off again, etc.
The program coding I will most likely not have a problem in. I'm proficient with C++ and Java, but I have never had to use such programs with an HTML environment - I know nothing about HTML.
My professor suggested I used DreamWeaver to generate the HTML page, which I probably can figure out rather quickly - but what I don't understand is how do I send the information to my program for processing. Is CGI on the right track?
I've been looking at the CGI tutorial posted by OVID, and so far it is very very informative and helpful - but I don't know if that's the right thing I should be looking at.
Would someone mind confirming my theory? Or pointing me in the right track? I would really REALLY appreciate it.
Thankyou Monks.
Edited by planetscape - added p tags
Re: PERL and HTML
by bradcathey (Prior) on Apr 19, 2006 at 00:28 UTC
|
You're on the right "track," so to speak. CGI is the ticket...with one exception. You may want to look at a templating module like HTML::Template (hopefully it will be installed on your web host) for returning the data to the HTML page. Burying your HTML in the CGI may be instructive, but H::T may be easier to adapt from whatever Dreamweaver generates. To return HTML results from CGI will require not only a knowledge of HTML, but of a more obfuscated version in CGI.
—Brad "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
| [reply] |
Re: PERL and HTML
by GrandFather (Saint) on Apr 19, 2006 at 00:37 UTC
|
Seems to me you are asking these questions too late, but maybe your course intends to simulate the pressure of trying to write something against an unrealistic deadline with unfamiliar tools?
However, you have come to the right place to get some help sorting out your problems. Your first task though is to do a little research. Take a look around CPAN for modules that mention HTML and Template in their names. Also take a look there for CGI and Template or Form related modules.
Good luck with the project (and try to fit some sleep in somewhere along the way).
DWIM is Perl's answer to Gödel
| [reply] |
Re: PERL and HTML
by spiritway (Vicar) on Apr 19, 2006 at 05:13 UTC
|
I would caution you about using WYSIWYG editors for HTML. I don't know how DreamWeaver does, but many HTML editors create such convoluted HTML that it's almost impossible to go on there and tweak it. I've found that I almost always have to tweak the HTML that's generated, so this might be a problem for you. This might not even apply with DreamWeaver; and it might be such a good program that you never have to tweak the HTML. But just keep this in mind as you're choosing your tools.
| [reply] |
|
I would caution you about using WYSIWYG editors for HTML.
I would agree with that, but having used Dreamweaver pretty extensively in the past, I've found it good for mockups, *and* it doesn't muck up your code by adding in superfluous tags like MS Word or Frontpage does. Since it's probably due in a couple weeks anyway, he could just download a trial version, too, if cost is an object.
Besides, it sounds like in the OP's situation, getting something together quick in Dreamweaver and tweaking it is probably easier than doing it by hand, especially considering he doesn't know HTML very well, and it doesn't seem to be the focus of the class.
| [reply] |
Re: PERL and HTML
by chas (Priest) on Apr 19, 2006 at 01:54 UTC
|
What has been said already, but a few comments: You can use
Dreamweaver or some other editor to create the initial webpage with form where the user's data is entered. The form should call your cgi script using the form "action". If you don't actually need to recreate the original page you could just have your script print out the results between <pre> </pre> tags. (This will appear on a new page. You also need the opening and closing html tags, but no other tags.)
(Getting your script in the right place with the right permissions executable by a web user and a page which is writable by the script to hold the results is part of the problem but separate from the perl programming part.) | [reply] [d/l] |
Re: PERL and HTML
by CountZero (Bishop) on Apr 19, 2006 at 05:48 UTC
|
Personally, I use Nvu as my favourite HTML-editor. It's free, it works on multiple platforms and its HTML-code is relatively straightforward and clean and therefore easy to "cut-and-paste" into your scripts or templates.For an entry into CGI, there is of course no way around Ovid's CGI-course. If you have any specific questions, you will find Perlmonks a good place to ask them. Please, ask only specific questions, add some code you have written, show the Monastery you made a genuine effort of finding a solution and you will find the Monks most helpful.
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
Re: PERL and HTML
by planetscape (Chancellor) on Apr 19, 2006 at 07:50 UTC
|
Kudos to you for starting this while there are a few weeks left before it's due. ;-)
I really like Arachnophilia for creating clean, straightforward HTML. If you are stuck using something (like FrontPage), that adds a lot of extraneous tags, I recommend HTML Tidy for cleaning up the mess.
HTH,
| [reply] |
Re: PERL and HTML
by holli (Abbot) on Apr 19, 2006 at 07:51 UTC
|
I know nothing about HTML.
Depending on your native language you might look at Selfhtml, a very good online html documentation. Sadly the english translation is far from being complete, but the german (original), french and spanish versions are not.
| [reply] |
Re: PERL and HTML
by jonadab (Parson) on Apr 19, 2006 at 12:24 UTC
|
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.
| [reply] [d/l] |
Re: PERL and HTML
by zentara (Cardinal) on Apr 19, 2006 at 12:24 UTC
|
If you are starting out in cgi, don't overlook "here docs" for printing out html manually from a cgi script. They are very handy, because they allow you to output html just as you would statically write it, and embed variables into it.
As an example, this will output code for a javascript popup
#!/usr/bin/perl
use warnings;
use CGI qw(:standard);
use strict;
print header();
print <<HERE;
<html>
<head>
<title>test of javascript</title>
<script language="JavaScript">
<!-- Begin
function launchwin()
{
window.open("../jspopup.html", "dialog", "width=300, height=250, scrol
+lbars=yes, resizable=yes");
}
// End -->
</script>
</head>
<body>
<center>
<form>
<input type=button value="Click here to try the JavaScript!"
onClick="launchwin()">
</form>
</center>
</body>
</html>
HERE
and here is a simple thank you page
print <<END_HTML;
Content-type: text/html
<HTML>
<HEAD> <TITLE>Thanks!</TITLE> </HEAD>
<BODY bgcolor="#ffffff"><br>
<P>Thanks for visiting our site : $username!</P>
</BODY>
</HTML>
END_HTML
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] [select] |
Re: PERL and HTML
by SamCG (Hermit) on Apr 19, 2006 at 21:28 UTC
|
"supposed to figure out what his cheapest OR fastest choice of travel is"
Haaahahahahaaaa! I guess your professor hasn't spent a lot of time with the "scheduling" of the NYC subway system. Or, for that matter, knows that there's one rate and transfers are free. Or maybe this is kind of a tongue-in-cheek question ;).
I've never found Dreamweaver to be that bad in terms of producing reasonable HTML, but you don't need it (and I'm not even sure it's really helpful) for this project. I think you could safely go either way.
update: Oh, and there's a secret, by the way. Shhhhhhhh. . . it's "Perl", not "PERL" (not critiquing -- just mentioning something that commonly grates on the nerves of some. . .)
-----------------
s''limp';@p=split '!','n!h!p!';s,m,s,;$s=y;$c=slice @p1;so brutally;d;$n=reverse;$c=$s**$#p;print(''.$c^chop($n))while($c/=$#p)>=1;
| [reply] |
|
|