in reply to Twirling baton progress indicator in Perl
That seems like a straight translation from C, if the printf still lost in there is any hint. That hypothesis would also explain doing this using a heavily copypasted switch construct, which is a common notion in C culture. But this is Perl, not C, so code smarter, not harder.
sub rotate_line { my $interval = 1; # Sleep time between twirls my $tcount = 0; # For each tcount the line twirls one incremen +t my @baton = ( '-', '\\', '|', '/' ); while ($interval) { $tcount++; print "$tcount\n"; print $baton[ $tcount % @baton ]; sleep $interval; } }
(Actually you can trivially do the same thing in C if you use a string to store the baton characters and then address single characters with a bit of pointer math, but I haven’t seen this a lot. C programmers rather like their switches for some reason.)
Your loop doesn’t terminate either, but it’s obviously only example code so I suppose it doesn’t matter.
There was also a CPAN module to provide a tied scalar that returns the next character in progression on every read, but its name escapes me and neither search.cpan.org nor Google are any help right now.
Makeshifts last the longest.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Twirling baton progress indicator in Perl
by Tanktalus (Canon) on Oct 11, 2005 at 03:19 UTC | |
by Aristotle (Chancellor) on Oct 11, 2005 at 11:49 UTC |