Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Here documents in blocks

by kcott (Archbishop)
on Dec 20, 2020 at 03:31 UTC ( [id://11125482]=note: print w/replies, xml ) Need Help??


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
    I think you'll agree that code is a lot cleaner; easier to read; and easier to maintain.

    I certainly do agree!
    Thanks Ken for this. Between this and other answers I think I can produce some much nicer code next time I am faced with this sort of problem.

    I suppose you have your reasons for using 5.16

    It's what is installed on the shared hosting...I have 5.32 on my laptop and even 5.28 on my mobile!

    The webhost are doing an upgrade over night at the beginning of January. They have not said what is being upgraded but I'm hoping that they will installing a later version of Perl although I won't be holding my breath.

    Like you, I normally work from home. My company doesn't have any offices so all my employees work remotely. We just have one small conference room for face to face meetings and I have an office next to that but unusually only visit about once a month and I have not been there since February due to the Pesky Pandemic which, here in the UK, seems to be getting worse rather than better - quite concerning as we are in the hospitality sector.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125482]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found