...not sure how to make it a webpage.
I would recommend having a look at HTML::Template. I like the idea of not having any HTML in my scripts but, as you may guess, in a template. The docs are very good and you should be able to pick it up fairly easily. If you have a reasonable grasp of arrays and hashes, as you indicate, that's a plus. Perhaps two simple examples might best demonstrate the idea.

The first one creates a web page with a message.

#!/usr/bin/perl use v5.12.2; use warnings; use strict; use HTML::Template; my $t = HTML::Template->new( filename => q{my_template_msg.html}, ); my $msg = q{Hello World}; $t->param(message => $msg); my $output = $t->output; say $output;
the template (my_template_msg.html)
<html> <head> <title>my template message</title> </head> <body> <p><TMPL_VAR message></p> </body> </html>
and the output
<html> <head> <title>my template message</title> </head> <body> <p>Hello World</p> </body> </html>
The second demonstrates displaying a list (something you would be interested in)
#!/usr/bin/perl use v5.12.2; use warnings; use strict; use HTML::Template; my $t = HTML::Template->new( filename => q{my_template_list.html}, ); my @colours = qw{red orange yellow green blue indigo violet}; # build an array of hashes (AoH) my @colour_params; for my $colour (@colours){ push @colour_params, {colour => $colour}; } $t->param(colours => \@colour_params); my $output = $t->output; say $output;
The template (my_template_list.html)
<html> <head> <title>my template list</title> </head> <body> <ul> <TMPL_LOOP colours> <li><TMPL_VAR colour></li> </TMPL_LOOP> </ul> </body> </html>
and the output (whitespace trimmed for brevity)
<html> <head> <title>my template list</title> </head> <body> <ul> <li>red</li> <li>orange</li> <li>yellow</li> <li>green</li> <li>blue</li> <li>indigo</li> <li>violet</li> </ul> </body> </html>
The benifits I see of this approach is that your Perl script still looks like a Perl script and your HTML still looks like HTML. Mixing them up, imo, always looks like a mess.

Get these working (holler if you get stuck) and put them somewhere safe. When you're developing something more complex you'll have something to fall back on that works which, for me at least, is an aide to restoring sanity. :-)

HTML::Template doesn't come with perl, you'll have to install it. There are plenty of posts and tutorials on that if you're not familiar with it. Again, shout if you hit a snag.

There are also modules that will help you with the previous/next buttons. I use the, imo, very excellent Data::Page. Perhaps another time.

Best of luck and let us know how you get on.


In reply to Re: Building a webpage with Perl by wfsp
in thread Building a webpage with Perl by relientmark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.