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

Using constantly changing varibles in perl. I have a file that uses tail to count every new line per second in a file. i am trying to change it so the varible $line_ps will not make a newline when printing. right now what im doing is:
system 'clear'; print "Lines P/s: $line_ps"; print "Average Lp/s: $average"; print "Total lines: $t-lines";
Im trying to make it so i do not need to clear it anymore. Where i can just have that variable printed change every time the variable changes.

Replies are listed 'Best First'.
Re: Printing changing variable in perl
by toolic (Bishop) on Feb 26, 2014 at 17:20 UTC
    You can use \r to back up and print over a line:
    use warnings; use strict; $|++; for (1 .. 3) { print "\r$_"; sleep 2; } print "\n";
      never, never, never suspected the existence of this! thanks Toolic
      For posterity, as pointed by ambrus you can find this in docs but i never understood what also wiki says: A carriage return, .. is .. a mechanism used to reset a device's position to the beginning of a line of text.

      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Printing changing variable in perl
by hippo (Archbishop) on Feb 26, 2014 at 17:42 UTC

    I suspect you might benefit from one of the many Curses modules on CPAN.