Re: Why doesn't this print when i omit the newline?
by ikegami (Patriarch) on Dec 16, 2014 at 14:42 UTC
|
Because $value ends with a Carriage Return, the second line overwrites the first.
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
|
|
$ perl -MData::Dumper \
-le '$Data::Dumper::Useqq=1; print Dumper("foo\r\n")'
$VAR1 = "foo\r\n";
$ perl -MData::Dump=pp -le 'print pp("foo\r\n")'
"foo\r\n"
| [reply] [d/l] [select] |
|
|
Reading the thread, I was also going to suggest this possibility, if ikegami had not done it before, because I had the same problem a couple of months ago and it took me at least 30 minutes to figure out that the line that appeared not to be printed was in fact overwritten by the next line (data produced on Windows and used on a Unix box, so that chomp removed the \n but not the \r).
| [reply] [d/l] [select] |
|
|
| |
Re: Why doesn't this print when i omit the newline?
by QM (Parson) on Dec 16, 2014 at 13:15 UTC
|
STDOUT is usually buffered by default. It's all queueing up until it sees a newline. Try setting $| = 1; before the loop, and add a sleep 5; between the prints. Then you should see something interesting.
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] |
|
|
Please don't manually add line numbers to your code. Then if I want to paste it, I have to remove them again. PerlMonks has an option in your user settings to enable line numbers so that you see them next to any code segment.
You didn't mention what output you are getting here, but on my system I immediately get the first line printed, and then five seconds later I get the first line plus a newline. Then immediately the second line, and five seconds later the second line plus a newline, and so on.
Ubuntu Linux 14.04 with Perl 5.20.1.
Ah, I get it... windows, and ikegami nabbed it below. :)
| [reply] |
|
|
Re: Why doesn't this print when i omit the newline?
by duelafn (Parson) on Dec 16, 2014 at 13:30 UTC
|
| [reply] |
|
|
| [reply] |
Re: Why doesn't this print when i omit the newline?
by toolic (Bishop) on Dec 16, 2014 at 13:16 UTC
|
It prints everything for me on 1 line when I comment out the 2nd print. I'm on perl v5.12.2, IO::All 0.46. | [reply] |
|
|
| [reply] |
Re: Why doesn't this print when i omit the newline?
by Anonymous Monk on Dec 16, 2014 at 13:22 UTC
|
0 use strict;0 use strict;
1 use warnings;1 use warnings;
...
And inspecting $index and $value seems to show that they are plain scalars and not objects with overloaded stringification. Are you printing to STDOUT or a file? Are you using select at all, or perhaps some other part of your program is? | [reply] [d/l] [select] |
|
|
The first print should print everything on one line and the second all the lines (with newline), as obsevered by toolic at Re: Why doesn't this print when i omit the newline?. I print to STDOUT and don't use select. I don't do anything else in my code - it's as shown in the example.
Thank you and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] |
|
|
Sorry, can't reproduce on Linux / v5.20 / IO::All v0.85. So I'll just throw out a couple more debugging guesses...
If you replace my $io = io $0; with my $io = [qw/foo bar/]; (and perhaps drop the use IO::All;) I hope it works?
Have you tried opening something other than $0?
| [reply] [d/l] [select] |