Your goal from all this code + HTML seems to be templated HTML, complete with if-logic and loops. I have a feeling that if you just take a glance at HTML::Template, you will quickly realize how much time and agony it can save you. In short, it does simple variable substition as well as, you guessed it, if-logic and loops! If you search the monastery, you'll find just loads of resources, not the least of which is HTML::Template Tutorial.

(Of course, there are other good templating systems out there, but HTML::Template covers exactly the functionality it appears you are looking for, so I think it's the best choice for you)

As your code stands at the moment, you seem to rate a #3 on Cody Pendant's scale of Perl/HTML interaction, which isn't bad. You could certainly do much worse! However, you've stumbled upon one of the main limitations of here-docs. So although I don't really address your original question (the other posts cover that pretty well), I just wanted to save you the trouble of trying to make your own templating system (#4 on the scale), which is a common next step up the ladder, but nearly always given up later in favor of a proven templating system (#5).

blokhead


In reply to Re: foreach and if inside <<ENDHTML? Can they work? by blokhead
in thread foreach and if inside <<ENDHTML? Can they work? by frogboy

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.