http://qs321.pair.com?node_id=5913


in reply to A whirleygig for a progress indicator for scripts

In that spirit, here's another idea for improving/generalizing your code.
package Whirley; sub new { my $type = shift; my $class = ref $type || $type; my $WHIRLEY_COUNT = -1; my @whirley = map chr, qw/32 176 177 178 219 178 177 176/; my $self = sub { $WHIRLEY_COUNT = 0 if ++$WHIRLEY_COUNT == @whirley; return $whirley[$WHIRLEY_COUNT]; }; bless $self, $class; } package main; my $whirley = new Whirley; while (1) { sleep 1; print STDERR "please wait: ", $whirley->(), "\r"; }
This packages up your whirley functionality into a package and a closure--you could even put it into Whirley.pm or something; then just use it and call it as illustrated.