I'd like to add my humble 2 cents here:

I've came from a HTML background so this node really drew my attention.

I think that although is possible to do a clean separation of presentation and logic, sometimes it's not the best way to do it, because you end up messing with the readability of the page. Let me clarify this with a (silly) example:

Let's say that a user of your web system should see a red background if he/she has a "0" level or a blue background if he/she has a "1" level.

So, you could do this in two different ways (i'm coding this in a freely, lazy way so dont evaluate my code, this is just an example):

First way (separating logic and presentation):
if ($u_level == 0) { $bgcolor = "#FF0000"; } else if ($u_level == 1) { $bgcolor = "#0000FF"; } # tons of code... print<<<HTML <HTML> <HEAD> <TITLE> DaWolf's silly example </TITLE> </HEAD> <BODY BGCOLOR="$bgcolor"> <!-- tons of content... --> </BODY> </HTML> HTML;
Second way (mixing logic and presentation):
# tons of code... print<<<HTML1 <HTML> <HEAD> <TITLE> DaWolf's silly example </TITLE> </HEAD> HTML1; if ($u_level == 0) { print "<BODY BGCOLOR=\"#FF0000\">"; } else if ($u_level == 1) { print "<BODY BGCOLOR=\"#0000FF\">"; } print<<<HTML2 <!-- tons of content... --> </BODY> </HTML> HTML2;
The advantage of the second way in my point of view is that you don't need to go all the way up to understand what $bgcolor means and why it have this or that value, so the code is more easily understandable and more practical to debug.

That's why I think separation should be avoided unless you are not used to deal with HTML.

As I've stated before, this is just my humble opinion.

UPDATE:

Quick explanation: I've never used a Templating system with Perl, so I can't really give my opinion on that, but I've just tried to show the best way ***for me*** to code my pages =:c)

Best regards,

my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");

In reply to Re: Code and html separation - always or mostly doable? by DaWolf
in thread Code and html separation - always or mostly doable? by kiat

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.