So over the past few months, I've tried to be very conscious about to writing better, cleaner code. I think I've improved a great deal but one spot that I frequently encounter that I'm still not quite sure how to handle is HTML generation. So take this line, for example, which makes me feel dirty:
my $load_js = "<script>function load_js(uri) { var script = document. +createElement('script'); script.src = uri; document.head.appendChild( +script); }</script>\n";
I know it's not good practice to mix content with code. But what's the best practice for a line like this? I didn't want to spread it over several lines as that would use up space. A HERE document is just plain ugly to look at in code and eats up space. And I didn't want to introduce any new modules or a template just to generate a few lines of javascript. I vaguely recall others recommend using __DATA__ for this kind of stuff but I guess I just don't see what the advantage to doing that is and it makes you have to go down to the end of the file to see what's happening.
Maybe what I'm going in the example code is perfectly fine. But I have a nagging feeling it isn't. If someone can set me straight and offer suggestions, I'd appreciate it.
PS to the haters: If you think it's in the best interests of the Perl community to tell me how dumb and worthless I am, go for it! I'm here for you.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Best practices: Generating HTML content by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |