I'm trying to send some e-mails in perl. Basically, the e-mails are going to consist of two generic chunks of text (strings) with some custom defined stuff in the middle. I'm trying to layout the first and second generic chunks of text as $msg_bdy_1 and $msg_bdy_2, and then print those strings into the e-mail object later on. So I'm trying to do something along these lines:

my $msg_body_1 = 'line 1\nline 2\nline3a\t\line3b\nline4\n\n'; my $msg_body_2 = '\n\nline 5\nline 6\nline7a\t\line8b\nline8\n\n'; my $other_crap = 'blah blah blah'; print $msg_body_1 $other_crap $msg_body_2;

However, when I write the code up, I don't want $msg_body_1 and $msg_body_2 to be one long line of unreadable crap. I'd like to be able to lay it out something along the lines of:

my $msg_body_1 = ' line 1\n line 2\n line3a \t \line3b\n line4 \n\n '; my $msg_body_2 = ' \n\n line 5\n line 6\n line7a \t \line7b\n line8 \n\n '; my $other_crap = 'blah blah blah'; print $msg_body_1 $other_crap $msg_body_2;

The problem is, when I actually write out the strings like the second example in my script, extra newline characters get added for every character break that I include (I don't only get character breaks on \n, I get character breaks on \n and every time I add an actual carriage return to the string with the "Enter" button).

I'd very much like to be able to lay out long, complex strings like this in an indented manner so that my code is readable later. But I don't know how to make the code both readable, and define the string with newlines and tabs only where I explicitly make calls to \n and \t.

I thought I could do somethings like:

qq/ some string stuff in here/x;

But apparently the /x modifer only works with m// and not the quote operators.

Am I missing something? Is this even possible in perl?

Thanks,
Brady C. Jackson


In reply to Formatting Strings Without Interpolating Whitespace by BJ_Covert_Action

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.