Moving the html out of your script using some templating tool is obviously the best solution.
Many have suggested the use of here-docs (
<<EOF).
I dislike heredocs. They make me feel old, they're ugly (no offense).
However, I do like being able to put literal linebreaks in string constants.
my $foo = 'First line
Second line
Third line';
But that's even worse than a here-doc. Fortunately, 90% of all cases where I want multiline string constants, it's about a piece of HTML. And HTML parsers don't really care about whitespace.
my $foo = '
First line<br>
Second line<br>
Third line<br>
';
That looks a lot better. But there's another problem:
my $foo = "
First line<br>
$second_line<br>
<a href=\"foo.html\">Third line</a>
";
Some people love backslash escapes, but I hate to escape my delimiter. But perl can handle alternative delimiters.
'' is
q// and
"" is
qq//. Instead of
/, any non-whitespace character can be used (note: if the character is alphanumeric, whitespace is _required_ after the operator's letters (
q mfoom eq 'foo'). You can use grouping characters (
() [] {} [] <>) and perl will keep track of nesting.
my $foo = qq{
First line<br>
$second_line<br>
<a href="foo.html">Third line</a>
};
Read about heredocs, quote-like operators, backslash escapes and DWIM (Do What I Mean) in
perlop.
2;0 juerd@ouranos:~$ perl -e'undef christmas'
Segmentation fault
2;139 juerd@ouranos:~$
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.