Current location: Hot Scripts Forums » Programming Languages » Perl » Show Progress Meter


Show Progress Meter

Reply
  #1 (permalink)  
Old 01-03-04, 02:23 PM
Greenhorn Greenhorn is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Show Progress Meter

I posted earlier re comparing files. Wrote a program which is complete except for one thing- I want to display a progress meter which is working, but not working correctly.

Here's the code...
Code:
#COMPARE COMMON FILES
undef $file;
print "\n\n\n\n\nCOMPARE - PROGRESS METER (each file scanned: \"x\" )\n\n\n";
foreach $file(@common) {
    $cse_file=$startdir.$file;
    $ftb_file=$startdir2.$file;
    print "x";
    if (compare($cse_file,$ftb_file) ne 0) {
        $old_ftb_file=$ftb_file;
        $different=1;
        $diff_mark=1;
        if ($ftbtag) {
            substr($ftb_file, -4, 0) = '.FTB';
            rename($old_ftb_file,$ftb_file);
            substr($file, -4, 0) = '.FTB';
            push(@renamed_ftb_files,$file);
        }
    }
    if ($diff_mark) {
        print "\n\nDIFFERENCE FOUND BETWEEN:\n";
        print "$cse_file"."\nand\n"."$old_ftb_file\n\n";
        undef $diff_mark;
    }
}
if (!$different) { print "\n\nNO DIFFERENCES FOUND IN ANY OF THE COMMON FILES!\n"; }
Now, each "x" shows up for each file scanned, but ONLY when the files are displayed as being different - not per file (the whole line of accumulated x's are only displayed when the "DIFFERENCE FOUND" line is displayed.)

i.e.
Quote:
xx

DIFFERENCE FOUND BETWEEEN:
c:\123.txt
and
d:\123.txt

xxxxxxxxxxxxxxxxxx

DIFFERENCE FOUND BETWEEN:
c:\somedir\456.doc
and
d:\somedir\456.doc

xxxxxxxxxxx

DIFFERENCE FOUND BETWEEN:
c:\789.java
and
d:\789.java
How can I get each "x" to show up one after another like a progress meter on EVERY RUN THRU THE FOREACH LOOP so I can be sure that the script isn't hung as opposed to just scanning large or multiple files?

Minor issue as it doesn't exactly affect performance, but the few brain cells I have left are failing me and I want to be sure the script is working when my boss turns the corner.

Much appreciated!
(Chas- care to take a stab at this?)

Adam

Last edited by Greenhorn; 01-03-04 at 02:27 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-03-04, 05:13 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Well, it looks like it should be printing the 'x' on every iteration to me. Try turning on autoflush and see if that helps:

Code:
#!/usr/bin/perl -w
use strict;
$| = 1; # Set autoflush to a non-zero value to turn on

# code below
When it does print the X's, is it the line of X's before or after the dif text?

~Charlie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-03-04, 08:02 PM
Greenhorn Greenhorn is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Well, when text is sent to the screen, the x's line are displayed above and the diff text below.

Then it just sits there with a blank line until the next diff file is displayed at which time any x's that have accumulated display as well (in a line as they should) and the diff text below.

Perhaps another cup of coffee should do the trick.

When I get to the office, I'll try your suggestion and FYI, this script is run on an WinXP machine running the latest ActiveState Perl release and the "screen" I'm referring to is the command prompt.

Adam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-05-04, 12:57 PM
Greenhorn Greenhorn is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Aw well- out of time to experiment. Script works so like they say "if it fits- you must acquit".

But I did find out that if I inserted a "\n" before the "x", then the screen will scroll downwards (but if I remove the "\n", the line will NOT appear.

So I figured I'd just go with a scrolling counter instead of a progress meter ie $i=1, print $i, $i++... which works fine. Just as long as I know the script hasn't hung.

Thanks for your assist Chas- much appreciated for taking a time out for me. I'll try thew autoflish next time I want a progress meter

Adam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-05-04, 01:08 PM
Greenhorn Greenhorn is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Looks like I owe you a beer. Autoflush did the trick (curiosity got the better of me). Excellent! Thanks chief.

Adam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 01-05-04, 02:13 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
No worries. Glad that worked for you.

~Charlie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
incorrect code, plz show me real code darkcarnival PHP 4 11-21-03 03:40 PM
Need help on a image slide show using php! xelanoimis PHP 2 10-16-03 07:51 PM
Signature doesnt show ?! pussycat Hot Scripts Forum Questions, Suggestions and Feedback 2 08-24-03 09:01 AM
please show me the code....... fui_koh Script Requests 1 07-07-03 02:04 PM
show me the code please......... fui_koh PHP 2 07-07-03 12:56 PM


All times are GMT -5. The time now is 08:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.