Just another Perl shrine | |
PerlMonks |
Is there a way to control when output gets printed to a file?by djw (Vicar) |
on Nov 28, 2001 at 22:20 UTC ( [id://128124]=perlquestion: print w/replies, xml ) | Need Help?? |
djw has asked for the wisdom of the Perl Monks concerning the following question:
I am using this application to capture, log, and graph out ethernet utilization information on a couple network devices at work. The application collects data at five minute intervals and prints out the result from each "run" to the logfile.
Initially I had it print out each run line (with data) to the console when I was building the tool (so I could watch it), but now I am using a logfile so that I can do weekly/monthly reports etc. The application creates a new logfile for each day at 8am and will continue to run till 5pm and then exit. Here is a snippet of log information:
Starting run 1\108 - In: 0.00 Out: 0.00 Time: 8:00 Starting run 2\108 - In: 0.05 Out: 0.10 Time: 8:05 ... Starting run 108\108 - In: 0.27 Out: 0.01 Time: 16:55 Utilization Graph Completed - Run length: 9 hours Generation complete. Now when I go and look at the current logfile for the day, I notice that no data actually gets printed to the file until run #74 (always) for each device (all seperate scripts in seperate dir's, with different logfiles). It prints up to the same point on line #74 and then doesn't print the remaining log info until program exit. It looks to me like its waiting until some kind of buffer reaches a certain point, then dumps it out, then continues without printing until my program exists. In my current program I am writing to the logs like this:
This prints out the first line of my logfile, then calls the snmpRun sub from the loop. Inside my sub is this bit of code:
Is there another way to do this so that the data does get written to the file as it hits the print lines? This isn't a big deal, but I'm curious to know. djw
Back to
Seekers of Perl Wisdom
|
|