Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Formatting Strings Without Interpolating Whitespace

by JavaFan (Canon)
on Jan 19, 2012 at 22:20 UTC ( #948856=note: print w/replies, xml ) Need Help??

in reply to Formatting Strings Without Interpolating Whitespace

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
Well, yes, of course. (Although, since you use single quotes in your code snippets, \n aren't interpolated -- but I'll consider that a copy-and-paste error). What do you expect Perl to do? Ignore your \ns? Ignore your newlines? Why should it? If you have newlines in your strings (be it because of \n, or a "real" newline) that you don't want, don't put them there!
  • Comment on Re: Formatting Strings Without Interpolating Whitespace

Replies are listed 'Best First'.
Re^2: Formatting Strings Without Interpolating Whitespace
by BJ_Covert_Action (Beadle) on Jan 19, 2012 at 22:22 UTC
    No, I expected perl to behave exactly as I said it is. My question is asking if there is a way to modify that behavior.
      Just do exactly what I said, don't include the newlines you don't want:
      my $msg_body_1 = "line 1\n" . "line 2\n" . "line3a \t \line3b\n" . "line4" . "\n\n" ;

        Having worked on a lot of code that did such things, I found that I had much fewer regrets with the almost subtly different:

        my $msg_body_1 = join '', "line 1\n", "line 2\n", "line3a \t \line3b\n", "line4", "\n\n", ;

        '.' binds tighter than a lot of things that are pretty common to include in a list of things to be joined together. The "no trailing '.' allowed" problem (an endless source of pain for me outside of Perl but in the form of "no trailing comma allowed") goes away when using comma.

        - tye        

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-01-27 04:18 GMT
Find Nodes?
    Voting Booth?