Hello,
I am trying to update the STDOUT dynamically.
For eg. I am trying to display a counter whose value should get updated int he same place,
#!/usr/bin/perl
$val = 10;
for ($i=0;$i<=$val; $i+) {
print "$val\n";
}
would print
0
1
2
3
4
5
6
7
8
9
10
What I am looking at is a clock like feature where the earlier output is overwritten by the current value of val.
2 11082 miller 1,089
Recognized Expert Top Contributor
Read this thread for discussion on flushing STDOUT http://www.thescripts.com/forum/thread603712.html
As far as overwriting the same line, you simply need a carriage return: "\r". You can read about them in the O'Reilly Camel book under "carriage returns". -
-
#!/usr/bin/perl
-
-
use strict;
-
-
local $| = 1;
-
-
my $val = 10;
-
for (my $i=0; $i<=$val; $i++) {
-
print "\r$val";
-
}
-
Consider a user wants to write to the same line, where subsequent lines could get shorter. The example (according to youre approach): - my $val = 0;
-
for (my $i=10; $i>$val; $i--) {
-
print "\r$i";
-
sleep(1);
-
}
would print
A solution to erase everything written before would be: - my $val = 0;
-
my $n = 0;
-
for (my $i=10; $i>$val; $i--) {
-
printf("\r%s\r$i", " " x $n);
-
$n = length($i."");
-
}
Greetz, Doc
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Powell |
last post by:
<?php
class FileRemoval {
var $fileNameArray, $isRemoved, $errorMsg = '';
function FileRemoval() { // CONSTRUCTOR
$this->fileNameArray = array();
$this->isRemoved = 0;
}
|
by: Graham Ashton |
last post by:
Hi. I'm having trouble flushing sys.stdout. I've written a small example
to illustrate my problem (see below). In short, I expect it to ping
"received hello", sleep for 5 seconds and then print "received world".
Instead I get nothing for 5 seconds and then both statements pop out at
once.
As you'll no doubt gather from the example, the problem I'm really trying
to solve is sending message back from one process to another via a pipe....
|
by: Leon |
last post by:
import os,sys
a = os.fdopen(sys.stdout.fileno(),"w")
b = os.fdopen(sys.stdout.fileno(),"w")
a.write("test1 ")
b.write("test2 ")
stdout result is
test1 test2
|
by: Joseph |
last post by:
Hi all,
I am doing my assignment and have a question ,how can I clear the standard
output(screen)?
following is the fake code:
=====================================
main(){
|
by: Oz |
last post by:
This is long. Bear with me, as I will really go through all the convoluted
stuff that shows there is a problem with streams (at least when used to
redirect stdout).
The basic idea is that my application (VB.NET) will start a process,
redirect its stdout and capture that process' output, displaying it in a
window.
I've written a component for this, and a test application for the component.
It allows me to specify a command to execute,...
| |
by: Oz |
last post by:
This is long. Bear with me, as I will really go through all the convoluted
stuff that shows there is a problem with streams (at least when used to
redirect stdout).
The basic idea is that my application (VB.NET) will start a process,
redirect its stdout and capture that process' output, displaying it in a
window.
I've written a component for this, and a test application for the component.
It allows me to specify a command to execute,...
|
by: velle |
last post by:
My headache is growing while playing arround with unicode in Python,
please help this novice. I have chosen to divide my problem into a few
questions.
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
on linux2
1)
Does " >>>print 'hello' " simply write to sys.stdout?
|
by: Steven Jones |
last post by:
I have a C program that prints out two lines as follows:
Line 1
Line 2
What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.
|
by: Christoph Haas |
last post by:
Evening,
I'm having trouble with running a process through Python 2.4's
subprocess module. Example code:
========================================================
def run(command):
run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for the process to return
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |