K
KJ
Hello,
I'm having a touch of trouble with a fairly simple program that I am
writing. It is a program that executes some interesting sorting
routines (I prefer using my own sort since it allows greater control
and debugging output, especially when the data set I'm using is very
large and "dirty" - ie. many erroneous values that I filter out during
the sort.)
Anyway, on to my question... The program has a statement such as
this:
$sortcount=0;
$debug=1;
while($condition)
{
if($debug)
{
$sortcount++;
if($sortcount%100000==0)
{
print(".");
}
}
<<SORTING CODE GOES HERE>>
}
My problem is this - with the program setup as above, the text gets
buffered for some reason (and doesn't appear on the screen at
run-time). I want the program to output a period (.) to the terminal
for every 100000 executions of the sort subroutine. When I execute
the code above, it outputs all of the periods after the sort
subroutine is finished. HOWEVER, when I run this code:
$sortcount=0;
$debug=1;
while($condition)
{
if($debug)
{
$sortcount++;
if($sortcount%100000==0)
{
print("$sortcount\n");
}
}
<<SORTING CODE GOES HERE>>
}
The program outputs the $sortcount number as the program is executing
and the sort is being performed.
My logic for why this is happening is this: PERL optimizes the code
(as all good compilers do) and erroneously thinks that since the "."
output is static, it is "unimportant" and can be buffered. In the
latter case, though, it sees that $sortcount is a dynamic variable
that is modified within the sort function's loop and deems it as
"important" - therefore outputting it to the screen without buffering
as the loop is executing.
Any ideas on how I can force PERL to deem that little period (.) as
important enough to output at runtime (and thus, disable print
buffering)? Any help or ideas that anyone can provide would be
greatly appreciated.
<<On a side note, I know there is a command "cerr <<" in C++ that
outputs a line of text as an "error" to the screen. Basically it is a
high-priority call to the print queue and followed by an immediate
buffer flush. Is there such an error output in PERL that I could use?
Keep in mind, this is for debugging purposes and will NOT be used in
the program on a regular basis... >>
Thanks,
KJ
I'm having a touch of trouble with a fairly simple program that I am
writing. It is a program that executes some interesting sorting
routines (I prefer using my own sort since it allows greater control
and debugging output, especially when the data set I'm using is very
large and "dirty" - ie. many erroneous values that I filter out during
the sort.)
Anyway, on to my question... The program has a statement such as
this:
$sortcount=0;
$debug=1;
while($condition)
{
if($debug)
{
$sortcount++;
if($sortcount%100000==0)
{
print(".");
}
}
<<SORTING CODE GOES HERE>>
}
My problem is this - with the program setup as above, the text gets
buffered for some reason (and doesn't appear on the screen at
run-time). I want the program to output a period (.) to the terminal
for every 100000 executions of the sort subroutine. When I execute
the code above, it outputs all of the periods after the sort
subroutine is finished. HOWEVER, when I run this code:
$sortcount=0;
$debug=1;
while($condition)
{
if($debug)
{
$sortcount++;
if($sortcount%100000==0)
{
print("$sortcount\n");
}
}
<<SORTING CODE GOES HERE>>
}
The program outputs the $sortcount number as the program is executing
and the sort is being performed.
My logic for why this is happening is this: PERL optimizes the code
(as all good compilers do) and erroneously thinks that since the "."
output is static, it is "unimportant" and can be buffered. In the
latter case, though, it sees that $sortcount is a dynamic variable
that is modified within the sort function's loop and deems it as
"important" - therefore outputting it to the screen without buffering
as the loop is executing.
Any ideas on how I can force PERL to deem that little period (.) as
important enough to output at runtime (and thus, disable print
buffering)? Any help or ideas that anyone can provide would be
greatly appreciated.
<<On a side note, I know there is a command "cerr <<" in C++ that
outputs a line of text as an "error" to the screen. Basically it is a
high-priority call to the print queue and followed by an immediate
buffer flush. Is there such an error output in PERL that I could use?
Keep in mind, this is for debugging purposes and will NOT be used in
the program on a regular basis... >>
Thanks,
KJ