Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The use of here documents is particularly useful ... because it allows you to keep the markup relatively free of escape characters that would otherwise reduce ... readability

(opinionated note on coding style, your preference may vary)

The HERE doc syntax was once a favorite here, but now it has been completely abandoned because:

  • 1) There were cases of too many 'escape' chars strewn about, (as mentioned elsewhere in this thread) which motivated a 'zero-tolerance' bias to *absolutely ban all ugly escape sequences*.
  • 2) There were cases where *some* of the variables were intended to be interpolated, but not others (e.g., with code-generation scripts) so it was not clear whether to use "EOT" or 'EOT' (as mentioned elsewhere in this thread).
  • 3) Indentation hassles (as mentioned elsewhere in this thread).

Because of these issues, we made a stylistic decision not to use HERE doc syntax anymore, and instead use the very flexible quotelike operator with all variables 'concatenated in' instead.

Thus, your example would become:

use strict; my $foo = 123.45; my $bar = "Martha Stewedprune"; ### --------------------------- print q^ ===== This is an example of text taken literally except that variables are expanded where their variable names appear. foo: ^.$foo.q^ bar: ^.$bar.q^ (Our *uninterpolated* variable names are "$foo" and "$bar" ... and we didn't need escape chars to tell you that). ^; ### ---------------------------

All you have to worry about is to make sure your quotelike delim character (caret) is never used in the document. If it is, just change it to something else. Moreover, you can indent this however you want without external module dependencies. Here, we just use comments to make the document visually distinct from the rest of the script.


In reply to Re: quotes in Perl (opinionated note on coding style) by dimar
in thread quotes in Perl by apotheon

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 wandering the Monastery: (4)
As of 2024-04-23 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found