LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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,994

Rep: Reputation: 76
\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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration