in reply to [OT] Why does newline in Windows print as having width?
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [OT] Why does newline in Windows print as having width?
by Lotus1 (Vicar) on Aug 18, 2018 at 05:09 UTC |