LanX has asked for the wisdom of the Perl Monks concerning the following question:

Maybe I'm missing something, but this behavior of x and p looks very odd to me:

lanx@nc10-ubuntu:~$ perl -de0 Loading DB routines from perl5db.pl version 1.3 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> p print "lula" 1lula DB<2> x print "horst" 0 1 DB<3> p print "lula" 1horstlula DB<4> p print "lula" 1lula DB<5> p print "lula" 1lula ... DB<11> x print "horst" 0 1 DB<12> x print "horst" 0 1 DB<13> x print "horst" 0 1 DB<14> p print "lula" 1horsthorsthorstlula

Cheers Rolf

UPDATE: improved example code.

UPDATE2: INTERPRETATION: Sleeping about it brought some insight about the fundamental differences between a debugger and a shell resp. REPL. I'm mostly using the debugger as a shell, expecting to get every line's output directly after typing. A debugger OTOH shouldn't alter the standard behavior of perl in order to find errors, and this naturally includes buffering.

While it's strange that p flushes and x doesn't, the wanted REPL behavior can be achieved by setting $| to 1.

Replies are listed 'Best First'.
Re: Debugger Bug?
by ikegami (Patriarch) on Sep 02, 2009 at 23:18 UTC

    It could be considered odd that "p" writes to (and therefore flushes) STDOUT, but I wouldn't say it's a problem.

    Or are you complaining about "x"? It's working properly. Did you mean to turn off buffering on STDOUT? or did you mean to do x "horst" instead of x print "horst"?

    Update: "x" flushes the output on both 5.8.8-linux and 5.10.1-Windows for me.

      I'm confused about the buffering, why should x turn on any buffering at all?

      DB<24> @arr=a..z DB<25> x print @arr 0 1 DB<26> abcdefghijklmnopqrstuvwxyz DB<26> print @arr abcdefghijklmnopqrstuvwxyz DB<27>

      please note at line 26 I just typed return !?!

      Cheers Rolf

      UPDATE: "This is perl, v5.10.0 built for i486-linux-gnu-thread-multi"

        Buffering is on by default. Try perl -e"print 'foo'; sleep 5; print 'bar'"

        please note at line 26 I just typed return !?!

        Reading from STDIN is documented to flush STDOUT. (One or both may need to be associated with a terminal for that to occur.)