LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-21-2005, 01:50 PM   #1
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Perl - printing progress on same line.


I have a script that prints out an iteration of numbers. The problem is the printed output scrolls. Exa:

123211 packets sent.
123212 packets sent.
123213 packets sent.
123214 packets sent.
123215 packets sent.

Simple code exa:

$iter++;
print "$iter packets sent.\n" if $verbose;

****

What I want instead is for only a single line to be printed but the number on that single line to increment ( no scrolling ). I've seen this before but can't find my example, so hoping someone can help me and/or point me to a web page that might have further info on it.

Thanks,
 
Old 06-21-2005, 03:21 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
\n will take the cursor on to the next line, scrolling as necessary
\r will take you to the start of the current line:
Code:
 $iter++;
print "$iter packets sent.\r" if $verbose;
 
Old 06-21-2005, 03:40 PM   #3
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Original Poster
Rep: Reputation: 30
That's what I was looking for. Thanks!
 
Old 08-05-2011, 09:00 AM   #4
Flimm
LQ Newbie
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 2
This doesn't work as expected if the line being printed is longer than the width of the terminal.
 
Old 08-05-2011, 09:53 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,966
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Quote:
Originally Posted by Flimm View Post
This doesn't work as expected if the line being printed is longer than the width of the terminal.
Since you chose to unearth a 6 years dead thread ... why don't
you post a solution to the THAT problem?



Cheers,
Tink
 
Old 08-07-2011, 12:35 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Since we seem to be getting a lot of replies to zombie threads lately, perhaps it is appropriate to mention that the Zero-Reply Threads pseudo-forum exists. It almost guarantees that the threads founds are current.
--- rod.
 
Old 09-03-2011, 01:21 PM   #7
Flimm
LQ Newbie
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 2
There is no real solution that I know of.

You can use GetTerminalSize like this:

use Term::ReadKey; ($width) = GetTerminalSize(); # don't forget the parens round $width

and then only print out out the first $width characters of a string. You can't print something out over two lines and then overwrite both lines.
 
Old 09-03-2011, 09:20 PM   #8
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,283

Rep: Reputation: 1089Reputation: 1089Reputation: 1089Reputation: 1089Reputation: 1089Reputation: 1089Reputation: 1089Reputation: 1089
There is a Perl variable ... see perldoc perlvar and look up "$|" ... that's dollar-sign vertical-bar.

This controls whether output is "buffered" pending the next newline character.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show a progress bar on the next line? Chowroc Programming 10 10-26-2005 10:27 PM
Perl - printing features satimis Programming 6 11-14-2004 11:45 AM
perl printing pantera Programming 1 06-02-2004 02:07 PM
command line printing rb3ng Linux - Newbie 3 04-22-2004 12:35 PM
Command line printing? HappyDude Linux - Software 2 10-25-2003 01:00 PM


All times are GMT -5. The time now is 04:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration