A Little Scripting

I just completed the 5th gig night in a row with Jack Swift.  If you haven’t, go check out the blog.  I haven’t posted there in a while, but the other guys have and there are pics.  Recordings too.

In the mean time I was playing with Perl a little this past week, and have something that may be of interest to some who would like a nice way to let a user know about how long a script has been slept.  I wanted to write a function that would basically provide a counter that updated every second (not hard to do at all), without actually creating a newline and thus adding to clutter in the terminal (that had me scratching my head).  So, after some Googline, here it is:

sub sleep_progress {
my $i;
for ($i = 1; $i <= $_[0]; $i++){
print “Slept $i out of $_[0] seconds\r”;
print “\n”;

So, then just call the function like this: sleep_progress(30), replacing 30 with some other number of seconds or a variable containin a number of seconds.  Whatever.  They key is the \r in the print function, which moves the cursor back to the beginning of the line, so that it can overwrite the line.  However, I couldn’t get this to work that way; nothing would display at all.  The $|++; part actually makes it work the way we want.