in reply to Here documents in blocks
G'day Bod,
I had a look through your post and came up with quite a few solutions; although, as I read through the other posts, I found most had already been covered. However, this one hasn't been addressed:
"... put every line in a separate print statement ..."
The print function takes a list. You don't need a massive column of print statements: sometimes you might need a few; for the HTML table code you showed, you really only need one.
I've reduced the HTML to bare bones text but the principle is the same. I've included a conditional line just as your code had.
$ perl -e ' print qq{line1\n}, qq{line2\n}, ($ARGV[0] == 20 ? qq{line3\n} : ""), qq{line4\n}; ' 19 line1 line2 line4
$ perl -e ' print qq{line1\n}, qq{line2\n}, ($ARGV[0] == 20 ? qq{line3\n} : ""), qq{line4\n}; ' 20 line1 line2 line3 line4
I think you'll agree that code is a lot cleaner; easier to read; and easier to maintain.
I suppose you have your reasons for using 5.16 — I'm stuck with that at $work too; but I use 5.32 at home. Thankfully, I work at home normally (nothing to do with the plague) so I can build utilities in 5.32 to automate a large part of my work; unfortunately, I need to use 5.16 for all legacy code. Anyway, the suggestions by others that I saw will work under 5.16 (templating systems, s///r, and so on).
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Here documents in blocks
by Bod (Parson) on Dec 20, 2020 at 11:16 UTC |