Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Here documents in blocks

by BillKSmith (Prior)
on Dec 19, 2020 at 19:50 UTC ( #11125464=note: print w/replies, xml ) Need Help??


in reply to Here documents in blocks

The book "Perl Best Practices" recommends factoring out such a heredoc into a subroutine. "The heredoc does compromise the indentation of the subroutine, but that's now a small and isolated section of the code..."
Bill

Replies are listed 'Best First'.
Re^2: Here documents in blocks
by eyepopslikeamosquito (Bishop) on Dec 20, 2020 at 09:01 UTC

    FWIW, all 255 Perl Best Practices (without the text from the PBP book) are available here. There are a number of items related to heredocs in the Values and Expressions chapter, the most relevant being item 42:

    Use a "theredoc" when a heredoc would compromise your indentation. This item offers two alternative ways to minimize compromising code indentation (which harms readability): i) factor out the heredoc into a predefined read-only constant at the file level; ii) factor out the heredoc inside a small subroutine (indentation is compromised but only in a small and isolated section of the code). Both methods do not indent the contents of the heredoc, so no error-prone tricks are required to adjust. Conway describes both methods as a "theredoc".

Re^2: Here documents in blocks
by Bod (Chaplain) on Dec 19, 2020 at 21:41 UTC
    The book "Perl Best Practices"

    Unfortunately my copy of that book is sat on a shelf in my office...I was last in my office back in February before the Pesky Pandemic turned the world upside down.

    Come to think of it, I filled up the biscuit tin the last time I was there!

      Speaking merely as a long time satisfied customer https://learning.oreilly.com/ (used to be called "Safari Books Online" back when I first subscribed) lets you get to electronic versions of all the ORA books as well as things from lots of other tech publishers as well as video courses. I've found it well worth what I pay them yearly that I don't spend on dead tree copies (then again I'm satisfied with reading things on my iPad).

      Alternately keep an eye out as Humble Bundle periodically will have ORA pdfs in a collection (e.g. this current one; but nothing (directly) perl related in this one though).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-04-20 00:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?