Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Perl and HTML

by golux (Hermit)
on Dec 02, 2012 at 23:47 UTC ( #1006767=note: print w/replies, xml ) Need Help??

in reply to Perl and HTML

Hi doo_the_dew,

For anything complex, Template::Toolkit is very useful, as has already been mentioned.

If it's something simple you can of course just use a perl CGI script as long as your server is configured to support it. On my server, as an example, I created these 3 files:

# head.html <head style="background:cyan"> <style type="text/css"> body { background: cyan; } </style> </head>


# body.html <body> <center> <h1>Simple CGI Example for <a href=" +1006655">doo_the_dew</a> </center> <hr>
and the file "index.cgi" (make sure it is executable if you're on a Unix/Linux server of course):
#!/usr/bin/perl -w # Libraries use strict; use warnings; use CGI::Carp qw{ fatalsToBrowser }; use IO::File; # IMPORTANT -- CGI scripts need to provide the header print "Content-type: text/html\n\n"; # Main program insert_file("head.html"); # Insert common header insert_file("body.html"); # Insert common body start # # YOUR CODE HERE # # Subroutines sub insert_file { my ($fn) = @_; my $fh = new IO::File; open($fh, "<", $fn) or die "Can't read file '$fn' ($!)\n"; foreach (<$fh>) { print; } close $fh; }

Hopefully that gives you something you can get up-and-running quickly. Once you need more power, you can always add Template::Toolkit, or even create your own HTML-generating libraries, as you desire.

say  substr+lc crypt(qw $i3 SI$),4,5

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006767]
[Corion]: marto: How's things? I hope the kids are fine and you too!
[Corion]: Oh yay. I wonder why a very simple change in a program doesn't elicit a diff, and now I see that my diff program seems to have a bug ;)
[1nickt]: marto thanks for asking, so far so good. A pretty modern stack and decent procedures, although rather too much home-built stuff (e.g. a logging role that should tries to duplicate Log::Any).
[Corion]: No. It's just that I'm comparing the same output file twice, instead of comparing the output files of the two runs %-)
[Corion]: Lo and behold, running a program with the correct input files yields the correct (and expected) output. Yay me.
[1nickt]: Got a MacBook and am expected to develop directly on it, ironic given the recent thread about that.
[marto]: Corion, some not too serious issues with the kids, hopefully, other than that just dealing with commuting by car again in the winter, not much fun so far, and there's no real 'bad' weather yet :)
[marto]: 1nickt, glad to hear it, I'm sure you'll bring improvements to their stack in due course ;)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-12-11 11:41 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (289 votes). Check out past polls.