http://www.perlmonks.org?node_id=948849

BJ_Covert_Action has asked for the wisdom of the Perl Monks concerning the following question:

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