Gossamer Forum
Home : General : Perl Programming :

Perl Print Question

Quote Reply
Perl Print Question
Ok i'm still very new to perl and i was wondering is there a way to have a script reprint over the same line... like a progress bar? i know if i do a

$i = 0;
while ($i <= 10)
{
print "$i\n";
$i++;
}

it will generate:

1
2
3
4
5
6
7
8
9
10

So is there a way to have it keep over writing itself so i can see the numbers still counting on my output... but the final print out will only show 10?

Thanks
Quote Reply
Re: [dipdill] Perl Print Question In reply to
Hi,

You could do this when running via SSH/Telnet:

Code:
for (my $i = 1; $i <= 10; $i++) {
print $i . "\n";
sleep 1;
}

You can onjly use "sleep" when running via Telnet or SSH, so calling this function from the browser will just print out 1-10, without the "loading" sense =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Perl Print Question In reply to
Not exactly what i am looking for... i can get it to print 1 number on each line... what i am looking for is a print statement that will print "1" then go back and overwrite "1" with "2"... then back and overwrite "2" with "3". the /n on the print sends me to a new line and prints the output on that line.

Hope this helps a little more with what i am looking for.

Thanks
Quote Reply
Re: [dipdill] Perl Print Question In reply to
Hi,

Ok, probably still not quite what your looking for - but I'm afraid its about as close as you're going to get;

http://www.ultranerds.com/...in/test.cgi?num_on=9

Code:
#!/usr/bin/perl

use strict;

my $count_to = 10;

my $self = "test.cgi";

########################

use CGI;
my $IN = new CGI;

my $num_on = $IN->param('num') || 0;

$num_on++;

print qq|
<script>
<!--
function autoChange()
{
var timeID = setTimeout("location.href= '$self?num_on=$num_on'", 1)
}
//-->
</script>
<body onLoad="autoChange()">
<p>$num_on</p>
</body>
|;

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!