carriage returns in HERE statements

B

bdz

I am running Ubuntu GNU/Linux Edgie.

I have a program that is using a here statement to print a message in
a terminal window.

sub info {
print << "HERE"
\~\~\~\~\~\~\~\~\~\~\~\~\n
Line 1 \n
Line 2 \n
Line 3\n Line 4\nLine 5 \n

\~\~\~\~\~\~\~\~\~\~\~\~\n
HERE
}

The message is printed out in this fashion

~~~~~~~~~~~~

Line 1

Line 2

Line 3
Line 4
Line5

~~~~~~~~~~~~

That is the carriage returns not marked by \n in the script are
printing to the
terminal as carriage returns giving me double spaced lines unless I
group all the lines on one line (as in 3,4,and 5.

I did not have this problem when I was using HERE statements under my
previous (obscure non-windows) operating system. Can anyone illuminate
this matter?
 
U

usenet

That is the carriage returns not marked by \n in the script are
printing to the terminal as carriage returns

You typed the program output (and made three typoos in the process) -
please don't do that. cut-and-paste instead.

Your program is apparently producing the correct output (we don't know
for sure, since you typed the output instead of cut-and-paste). When
you use a heredoc, every single character is included (including any
newlines that you put in the text by way of hitting your ENTER key).
If you terminate a line with a \n you get two newlines - one that you
included by hitting ENTER and one that you included by typing \n.

If you saw different behavior from another program it's probably
because $\ had been redefined.
 
B

bdz

Thanks for the explanation. I am sorry I typed it, i was trying to
simplify. However knowing that the newlines that are in the text will
print to the terminal without having to put in a \n solves my problem.
Amigas do not respond that way when here documents are used in a
terminal but I am aiming for cross OS capability.

Thanks for your useful comments on my typing. I see the three
"typoos", forgetting the ; after "HERE" and Line5 instead of Line 5
in the output and the code should have produced two blanks before the
final set of tildes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top