OK... I've written a script that runs on win32 which takes some time to run. Instead of just leaving the screen blank, I wanted to show a text based progress indicator. The way I chose to do this is to show completed/total and update it on each iteration. Now the way I've gone about this seems rather hackish to me, but I couldn't find a better way. What I've actually done is print ^H's (One character, not two) to backspace over the previous display and then reprint. Here's the whole sub..
sub GetAgedComps { my $filter = FILTER_WORKSTATION_TRUST_ACCOUNT; my $level = 2; my $fudge = 120960; my $conversion = 86400; my ($server, $age, $silent) = @_; my (@machines, $comp, %info, %accts, $buf, $x); print " Pulling information from $server...\t\t" unless $silent; if (UserEnum($server, \@machines, $filter)) { print"[OK]\n" unless $silent; } else { print "[FAILED]\n" unless $silent; die " Unable to retreive information from $server: $!\n" } my $count = @machines; print " Checking for aged accounts...\t\t\t" unless $silent; foreach $comp (@machines) { unless ($silent) { $x++; #note, the funny char is a ^H print "" x length($buf) if $buf; print $buf = "[$x/$count]"; } unless (UserGetInfo($server, $comp, $level, \%info)) { die "\n Error retreiving information for $comp: $!\n"; } if (($info{'passwordAge'} - $fudge) / $conversion > $age ) { ($accts{$comp}) = int (($info{'passwordAge'} - $fudge) +/ $conversion); } } print "\n" unless $silent; return \%accts; }
Now my question is: is there a better way to do it? It works fine, but that doesn't mean that there isn't a more apropriate way to handle it.

Thanks,
Rich

PS - this pulls NT machine trust accounts that haven't been accesed in over a certian number of days. I was planning on posting it here once I have it cleaned up.


In reply to Manipulating cursor position when printing to STDOUT by rchiav

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.