Perl Redirection

Hi,
I have a Perl script that finds some files based on some criteria and then it processes the file contents using some logic.
Extract:

print "Started ... ";
my $command = "<unix command>";
@arr=`$command`;
$size=@arr;
print "Size: ".$size

If I turn on the Perl debugging option then I get a warning like:

Use of uninitialized variable in line number so and so
after the initial lines are printed.

My question is that whenever I redirect the output of this script to some text file the debug warnings are written to the text file before the print statement in red is printed.
The flow of the script also does not conform to this weird behavior. Any idea folks?
Thanks.

You should always have

use strict;
use warnings;

in your code.

Once there, listen to their error & warning messages and clean them up.

"Use of uninitialized variable in line number so and so" is telling you that you are trying to print a variable with no value. Use an 'if' condition to test this before you print it or initialize the variable with some value by default.

To remove this message from your output, redirect stderr when you submit your script.

./myprog 2> /dev/null

should do the trick, but it won't get rid of the warning.

stderr is unbuffered.

stdout is fullbuffered/line buffer... Thats why you get the errors/warning before output.

Declare the undeclared variables first, and continue programming.

Thanks a lot for your suggestions :).