n00b has asked for the wisdom of the Perl Monks concerning the following question:

Ok my question is can I make 2 diffrent .pl files link them so they run of each other and one of them have the html code init. next I know I can use html in my cgi perl code but how. can it still do all the things HTML does like tables and stuff. and if someone would not care to help me more could they do a quick example for me. thanks so much

Replies are listed 'Best First'.
Re: Basic CGI
by Chady (Priest) on Apr 06, 2001 at 10:26 UTC

    I suggest you read a bit more about it... here's a quicky example(untested)

    ### file 1 called functions.pl

    #!perl sub &printHtml { # here you can print your html.. # you can do so using CGI.pm or you can manually print them.. # I assume you don't know what CGI.pm is also, so you can do this: print "Content-type: text/html\n\n"; print <<EOF; <HTML> <body> <h1>Hello World!</h1> </body> </html> EOF } 1; # return true.

    ### Here is the main file index.pl

    #!perl require './functions.pl'; # so here you can do this : &printHTML;

    you have a lot to read, I suggest you get yourself a good Perl book and start learning.


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Re: Basic CGI
by snapdragon (Monk) on Apr 06, 2001 at 12:54 UTC
    the idea of the two files that Chady posted is probably what you want in terms of how to have two files, where one file contains HTML embedded in functions and one file contains the the 'controlling' parameters (i.e. which functions to call).

    All I'd add is be careful when using the here document tags. As Chady showed the here document allows HTML to be written as raw text without having to escape quotes, put in print statements etc. The basic syntax is to have a print << followed by the ending tag. So you end up with something like:

    print <<Ending_tag; Ending_tag

    For the ending tag to work there are a few *important* rules to remember:

    • The ending tag must be all the way on the left hand side with no spaces before it and there can be nothing else on the line (not even a comment).
    • The line does not end with a semi-colon
    • You can call the tag pretty much anything, but it is case sensitive.

      Have fun playing around with it (and Perl as a whole).

Re: Basic CGI
by virtualsue (Vicar) on Apr 06, 2001 at 21:19 UTC
    Hey n00b,

    Do you have some sort of project in mind, or are you just trying to learn perl CGI programming (or both)?

    How about trying "perldoc CGI"? Perl comes with a lot of built-in documentation. If you want to see it in a browser, go to this Perl documentation site

    Have you looked at Lincoln Stein's CGI.pm Site

    Can't say I fully recommend his CGI.pm book, however, though others may like it. In particular, the reference guide in the back of the book stinks. I'd like to give you a positive recommendation, but that's the only book I have on the subject. ;-)

      virtualsue Well I know perl and now just starting to learn cgi I Kind of have a project in mind bt of course need to learn cgi first. I am trying to learn it and am slowley getting to know and like it thanks. and that is the reson to come here is to try and learn.
        Were those links I posted helpful, along with the other replies you've already got, or is there more you'd like to discuss?