![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
Way of the Spinner (repost)by !unlike (Beadle) |
on Jan 17, 2003 at 11:49 UTC ( #227652=perlquestion: print w/replies, xml ) | Need Help?? |
!unlike has asked for the wisdom of the Perl Monks concerning the following question:
For those of a nervous disposition, reasurance your Perl code is actually processing something is a good thing. When writing code executed from the command line a spinner is a popular choice of providing this reassurance.
When I first thought about doing this (many moons ago) I produced the following code: After a while, and much learning, I realised I could shorten this to print STDERR $spinner[$i++ % @spinner]. I then went away happy thinking that was the best anyone could do. Until the other day. Out of the blue the following code "popped" into my head: I see this as an improvement on my last attempt for the following reasons: 1) It's more modular so I can have multiple spinners within one script, all giving different output (not sure when you'd want this mind!) 2) proves I have at least got a reasonable grip on how closures work 3) it is only fractionally slower than just printing $spinner[$i++ % @spinner] I'd be interested in anyone elses thoughts on this code and any suggestions on how to do this differently/"better"/whatever !unlike "The price if ignorance, which is of course that you must learn from those with knowledge." Scorates (paraphrased)
Back to
Seekers of Perl Wisdom
|
|