Hello Lotus1,

I assume that the windows for both your Linux and your Windows command prompts are exactly 80 characters wide? If so, the following one-liner:

perl -we 'print "-" x 80; <STDIN>;'

on Linux (actually Cygwin, in my case) will show the cursor at the end of the line; but the equivalent script on Windows:

perl -we "print '-' x 80; <STDIN>;'

shows the cursor on the following line. This means that terminating the line with a carriage return \r will take the cursor back to the beginning of the line of hyphens on Linux, but on Windows it cannot do so because the cursor is already on a new line befor the carriage return is printed. Likewise for Perl’s \n character: printing a newline at the beginning of a line results in the extra blank line you are seeing.

If you know that your command window will always be exactly 80 characters wide, you can get the output you want on Windows by simply omitting the newline character altogether:

print "-" x 80; print "2\n";

— but, of course, this is not portable either across platforms or across Windows command prompts of different widths.

You may be able to achieve what you want using the Win32::Console module (but so far I haven’t figured out how to use it :-( Why is the Synopsis missing from its documentation??).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: [OT] Why does newline in Windows print as having width? by Athanasius
in thread [OT] Why does newline in Windows print as having width? by Lotus1

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.