|
Here is one of those little spinning progress indicators,
to amuse the user while your program is doing something
that takes a long time.
#!/usr/bin/perl -w
use strict;
package Spinner;
sub new
{
my ($class) = @_;
bless {
_position => 0,
_picture => [ '|', '/', '-', '\\', '|', '/', '-', '\\' ]
}, $class;
}
sub spin()
{
$_[0]->{_position} = ($_[0]->{_position} + 1) % 8;
print $_[0]->{_picture}[$_[0]->{_position}];
print "\r";
}
package main;
$| = 1;
my $spinner = Spinner->new;
foreach (1..20) {
$spinner->spin;
sleep 1;
}
|