I know how much we all love when people who haven't been using perl for any length of time bemoan that perl code looks like line noise, or that it's a write-only language. So, I think we should at least not do the same in reverse.

At no point when I was writing C would I have imagined using either switches or "pointer arithmetic" for this. I would have done basically the same thing you just did, but in C.

void twirl_baton() { static int position = 0; static char* baton = "-\\|/"; printf("%c\b", baton[position++ % 4]); }
Which is exactly the same, except it allows work to get accomplished while the baton is twirling, as you just keep calling twirl_baton every so often in the code. Which I'm sure you would have done in perl if it weren't that the OP asked specifically about sleep in their misdiagnosis of their problem. Yes, under the covers, baton[position++ % 4] is pointer arithmetic, but abstractly it is no more pointer arithmetic than your perl usage. For example, array usage is taught way before pointers in most C courses and books.

That's not to say that some people didn't learn switch statements with the rotating baton - but my experience doesn't show it to be indicative or cause/effect. I would think this to be more indicative of other languages where arrays aren't so easy to do - e.g., REXX or shell. Or languages where many beginners show up, but never advance to the point of seeing/using arrays (I can think of many QBASIC "programmers" falling into this category - I'm sure there are many VB users as well, although with common usage of VB being GUI, Windows Registry, and database interactions, I would think VB would have a lower percentage of these users than previous iterations of BASIC).


In reply to Re^2: Twirling baton progress indicator in Perl by Tanktalus
in thread Twirling baton progress indicator in Perl by axl163

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.