Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris


by kakarot (Initiate)
on Dec 16, 2000 at 22:06 UTC ( #47053=perlquestion: print w/replies, xml ) Need Help??
kakarot has asked for the wisdom of the Perl Monks concerning the following question:

How do you create a web site purely in perl (.pl) and not in html (.html)

Replies are listed 'Best First'.
Re: Websites
by Petruchio (Vicar) on Dec 16, 2000 at 22:24 UTC
    I don't think you quite have the picture, here.

    Web sites are made of HTML. You can use Perl to produce HTML, which is what you're seeing when you see a page whose name ends in .pl You're still going to be dealing with HTML, though.

    Programs which generate HTML in the way you're talking about are called CGI programs. You should learn to write CGI programs in Perl, using the module. There's plenty of tutorials and documentation out there. You'll need an account where you're allowed to run your own CGI programs.

    Good luck.

(Ovid) Re: Websites
by Ovid (Cardinal) on Dec 16, 2000 at 22:18 UTC
    You should learn the HTML shortcuts that are provided with the CGI module. The following subroutine from this web page generates a Web page using Perl, with no HTML in the Perl, which is what I assume is what you are asking for.
    sub create_web_page { my %in_data = ( @_ ); my $file = "C:/windows/desktop/cgi_course/appendices/appendi +x2.html"; # Always check return codes! open OUT, ">$file" or die "Cannot open $file for writing: $!\n"; print OUT $q->start_html( -title => "URL and HTML Character Codes" +, -style => { src => '../style.css', type => 'text/css' }, -author=> '' ), $q->h1( 'URL and HTML Character Codes' ). $q->p( 'This Web page was created with Perl, using and s +everal other modules.', 'See the source code at the end of the page for how I cr +eated it.' ), $q->p( 'Some may object to my listing HTML character codes for +"unused" characters', 'such as ASCII 127 (hex 7F), but browser support for the +se characters is spotty.', 'Different browsers will choose to render these characte +rs or not (e.g. IE 5.01', 'recognizes € as the Euro "" symbol, but Netsc +ape 4.7 does not). Owing', 'to this difficulty, I have elected to leave things as t +hey are and let you pick', 'and choose the characters you need as you like.' ), $q->em( 'Amongst other things, the program reads its source code + to create this page.' ), $q->p( ' ' ), $q->table( $q->Tr ( $q->th( $in_data{ headers} ) ), $in_data{ data } ), $q->p( 'Back to the ' . $q->a( { -href => '../index.html' }, 'ta +ble of contents' ) . '.' ), $q->pre( { class => 'program' }, $in_data{ code } ), $q->end_html; close OUT; }
    However, this is usually a bad idea if you want to create large, scalable sites. has a great discussion of why templates are typically the way to go. If the Template Toolkit is too daunting, try Using HTML::Template. It's a simpler solution and very easy to implement.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Websites
by Fastolfe (Vicar) on Dec 16, 2000 at 23:35 UTC
    If you're trying to build a 100% dynamic web site and avoid static content (for whatever reason), you may wish to consider things like Apache::Mason and HTML::Template. Perl does a good job of doing things like this when you combine it with mod_perl, but at the risk of being anti-Perl for a moment, there are other tools out there specifically written to do things like this, such as PHP. Alternatives might suit your needs a bit better than Perl alone would, but since you've given no indication of what you're trying to do, you're on your own as far as evaluating suitability to purpose.
Re: Websites
by Elgon (Curate) on Dec 17, 2000 at 03:09 UTC

    I think that some bits of information you require have been given by more experienced people but here are my thoughts:

    'Websites' are pretty much in HTML whether static or dynamically generated, only the source of the code changes.

    Perl is good for generating dynamic content and is a really useful module, although the HTML language it actually generates is crufty to read (bad formatting) - fortunately browsers don't mind ;-)
    It is also quite easy to learn - if you intend on using CGI a lot, the book CGI Programming with Perl is pretty good. Although, as pointed out there are online tutorials, go - here - for some given by Google.

    A final note and on something I know very little about: be aware of security and safety issues - it can be quite easy to overlook something which can really give your database a bad day if you're not careful!

    Hope this helped - enjoy. Elgon.

    "All characters are incidental" - Kurt Vonnegut

    Update: Check out this link for 'issues', many thanks to epoptai

Re: Websites
by lolindrath (Scribe) on Dec 17, 2000 at 04:22 UTC
    Also consider asking your administrator to setup the webserver so that can be the default document. This makes it easier than trying to make a work around to get index.html to be dynamic.


      If you're using apache, you can just put the DirectoryIndex directive into your .htaccess file and not bother your poor, overworked sysadmin :) e.g.,

      DirectoryIndex index.cgi index.scm index.html index.htm

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://47053]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-03-19 19:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.