Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Here documents in blocks by kcott
in thread Here documents in blocks by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-19 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found