carriage returns in HERE statements

Discussion in 'Perl Misc' started by bdz, Feb 26, 2007.

  1. bdz

    bdz Guest

    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"
    Line 1 \n
    Line 2 \n
    Line 3\n Line 4\nLine 5 \n


    The message is printed out in this fashion


    Line 1

    Line 2

    Line 3
    Line 4


    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?
    bdz, Feb 26, 2007
    1. Advertisements

  2. Guest

    On Feb 26, 10:28 am, "bdz" <> wrote:

    > 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.

    The best way to get a good answer is to ask a good question.
    David Filmer (
    , Feb 26, 2007
    1. Advertisements

  3. bdz

    bdz Guest

    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.
    bdz, Feb 27, 2007
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Sep 6, 2003
  2. Schroeder
    Jim Gibson
    Jan 26, 2005
  3. Mario Vargas

    Replacing Carriage Returns in VB.NET

    Mario Vargas, Oct 21, 2003, in forum: ASP .Net
    Dragos Marian Barbu
    Nov 10, 2003
  4. Brian
    Craig Deelsnyder
    Jun 17, 2004
  5. Steve Anderson
    Steve Anderson
    Jun 21, 2004

Share This Page