Live data from Hacker News

Easily plot realtime data (via Perl and GnuPlot)

users.softlab.ntua.gr

1–10 of 15 posts

Re: Easily plot realtime data (via Perl and GnuPlot)

#4
Line 5 just made me spill my coffee (or I need to drink some more). Since STDOUT is the default filehandle, there is no need to muck around with that anachronism. A simple $| = 1 would suffice. This idiom was once useful for setting autoflush for a filehandle other than STDOUT, but this is not the case here. For a lengthier discussion on this, including the apologies of Randal Schwartz for coming up with it (when admittedly other facilities were not available for the very specific use case it addresses) see [0].

[0] http://stackoverflow.com/questions/196754/what-does-selectse...

Re: Easily plot realtime data (via Perl and GnuPlot)

#6
post #4

Line 5 just made me spill my coffee (or I need to drink some more). Since STDOUT is the default filehandle, there is no need to muck around with that anachronism. A simple $| = 1 would suffice. This idiom was once useful for setting autoflush for a filehandle other than STDOUT, but this is not the case here. For a lengthier discussion on this, including the apologies of Randal Schwartz for coming up with it (when adm…

Back in 2008 (when this was written) "perldoc -q flush" suggested exactly that gem :-) I admit I've more or less abandoned Perl since then (scripting in Python for everything).

Re: Easily plot realtime data (via Perl and GnuPlot)

#7
post #4

Line 5 just made me spill my coffee (or I need to drink some more). Since STDOUT is the default filehandle, there is no need to muck around with that anachronism. A simple $| = 1 would suffice. This idiom was once useful for setting autoflush for a filehandle other than STDOUT, but this is not the case here. For a lengthier discussion on this, including the apologies of Randal Schwartz for coming up with it (when adm…

A nicer way to do it that's not as obtuse, since 5.6 is to do

  use IO::Handle;
  *STDOUT->autoflush(1);
This ends up far clearer than either example, and the idiom even extends easily to all file handles, lexical or otherwise.

EDIT: That being said,

  system("sleep 0.02") == 0 or last
is even worse. There is no need to go out to a shell or even an external program for that.

  use Time::HiRes;
  ...
  sleep(0.02);
  ...
Not only will that work on far more systems, it will use less resources and is available to all perl's since 5.7.3 (development release from March 2002, first in stable release from July 2002).

Re: Easily plot realtime data (via Perl and GnuPlot)

#8
post #4

Line 5 just made me spill my coffee (or I need to drink some more). Since STDOUT is the default filehandle, there is no need to muck around with that anachronism. A simple $| = 1 would suffice. This idiom was once useful for setting autoflush for a filehandle other than STDOUT, but this is not the case here. For a lengthier discussion on this, including the apologies of Randal Schwartz for coming up with it (when adm…

A nicer way to do it that's not as obtuse, since 5.6 is to do use IO::Handle; *STDOUT->autoflush(1); This ends up far clearer than either example, and the idiom even extends easily to all file handles, lexical or otherwise. EDIT: That being said, system("sleep 0.02") == 0 or last is even worse. There is no need to go out to a shell or even an external program for that. use Time::HiRes; ... sleep(0.02); ... Not only w…

Thanks for this. Note that the "sleep" is not part of the plotting script - it's just an example that generates data for plotting. I updated the page with your suggestion.
Post reply on HN