Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Progress Bar in Perl script

by regexes (Hermit)
on Mar 13, 2013 at 09:40 UTC ( [id://1023155]=note: print w/replies, xml ) Need Help??


in reply to Re: Progress Bar in Perl script
in thread Progress Bar in Perl script

I've been away from Perl for too long... I hope I'm not misunderstanding some fundamental principal here...

When I run this code from the command line, what I don't understand is how the "spinner" is printing over itself to the screen.
I understand that @sail is being interated through by incrementing $sail, but what part of this code is making the contents of @sail print on top of each other, i.e. making the "spinner" effect?

my @sails = map { "\b$_" } qw{- \ | /}; my $sail = 0; { local $| = 1; print q{Running: }; for (0 .. 1000) { system $cmd and die qq{'$cmd' failed! $? : $!}; print $sails[$sail++ % @sails] if not $_ % $skip; } }


Any help here? What am I overlooking?

Replies are listed 'Best First'.
Re^3: Progress Bar in Perl script
by kcott (Archbishop) on Mar 13, 2013 at 14:46 UTC

    Each of the sails is created by prepending a "\b" to the spinner character:

    my @sails = map { "\b$_" } qw{- \ | /};

    "\b" is a backspace character; so, when each sail is printed, it deletes the previous one. In the initial state, "Running:" is followed by two spaces (print q{Running:  };); the second space is overwritten by the first sail.

    "\b", and other special characters, are listed in perlop: Quote and Quote-like Operators.

    -- Ken

      D'oh! Thanks! I knew I was overlooking something...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1023155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found