Hello, I am new to CGI and I am trying to do some web stuff and the one problem that I keep running into is figuring out the proper way to generate the html. For example I want to create some div elements like this:
<div id="div-test"> <div>Hello</div> <div>GoodBye</div> <div>Friend</div> <div>Adios</div> <div>Amigo</div> </div>
My Perl code that generated the above:
my @fields = qw(Hello Goodbye Friend Adios Amigo); print header, start_html( -title => "testme"), div ( { -id => "div-test" }, # instead of doing this, can i create a div just by loopin +g # through @fields div("Hello"), div("GoodBye"), div("Friend"), div("Adios"), div("Amigo") ), end_html;
As the Perl Doc suggested, I've been using CGI standard to create my html, but I am not completely familiar with how to use it. I want to insert a foreach loop after my initial div to create a set of divs for each element in the array @fields. But when I do this, it throws a syntax error. I also noticed that I just can't insert a if statement or other Perl operations in a html declaration. How do I do this? If anyone can help, it would be great. Thank you for your time.

In reply to Calling functions in middle of CGI HTML declarations by dr.jekyllandme

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.