Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Progress indicator during a filehandle while

by oblikon (Initiate)
on Aug 29, 2007 at 17:58 UTC ( [id://635885]=perlquestion: print w/replies, xml ) Need Help??

oblikon has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I'm a newbie here, and so I may be doing things in a very evil way, but I'm trying to write a script that builds an imapsync command, and then launch it.

I have it working, but when i call my script, it doesn't print the "." I use for a progress indicator until after the other script has run.

Anyway, here is the offending code:

open(IMAPSYNCOUTPUT,"$imapsynccommand|"); open(LOGFILE,">>$imapsynclog"); my $num = 1; while (<IMAPSYNCOUTPUT>) { print LOGFILE "$_"; if ($num == 1) { print "."; $num++; } elsif ($num < 10) { $num++; } else { $num = 1; } }
I'd appreciate any help you could give,

Thanks,

Oblikon

Replies are listed 'Best First'.
Re: Progress indicator during a filehandle while
by FunkyMonk (Chancellor) on Aug 29, 2007 at 18:05 UTC
    You need to turn autoflush on with $| = 1;. See autoflush in perlvar.

Re: Progress indicator during a filehandle while
by agianni (Hermit) on Aug 29, 2007 at 18:34 UTC
    You might consider using Smart::Comments for your progress indicator.
    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
Re: Progress indicator during a filehandle while
by duckyd (Hermit) on Aug 29, 2007 at 22:24 UTC
    You might also consider using $., the current line number of the last filehandle accessed, like so:
    while(<DATA>){ print '.' if $. % 10 == 0; }
Re: Progress indicator during a filehandle while
by oblikon (Initiate) on Aug 29, 2007 at 19:30 UTC
    the $| = 1; worked perfectly, thank you

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-20 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found