develooper Front page | perl.beginners | Postings from August 2009

Re: Code for making the 'clock'

Thread Previous | Thread Next
From:
Chas. Owens
Date:
August 19, 2009 08:55
Subject:
Re: Code for making the 'clock'
Message ID:
58ce48dc0908190855s39d8dadcrabad85ca2c81e67c@mail.gmail.com
On Wed, Aug 19, 2009 at 11:03, Tony Esposito<tony1234567893@yahoo.co.uk> wrote:
> Anyone have the code that make the 'clock' show when a Perl program is running?
> What I mean by the 'clock' is the command-line movement that sequentially does the following (in place):
>
> - \ | / - \ | /
snip

#!/usr/bin/perl

use strict;
use warnings;

my @spinner  = qw{ - \ | / - \ | / };
my @throbber = qw{ . o O o };

$| = 1;

print "waiting: ";
while (1) {
	my $spinner_frame  = shift @spinner;
	my $throbber_frame = shift @throbber;

	print "$throbber_frame $spinner_frame";

	push @spinner, $spinner_frame;
	push @throbber, $throbber_frame;

	#wait a tenth of a second
	select undef, undef, undef, .1;

	print "\b\b\b";
}



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About