tags:

views:

135

answers:

2

Is there a way to output debug messages in Perl that are not piped? I have a Perl script that I use in a pipe but I really want to print some diagnostic information to the screen instead of to the pipe.

+9  A: 

Are you piping both stdout and stderr? If not, write to the one you're not piping :)

e.g.

print STDERR "This goes to standard error";
print STDOUT "This goes to standard output";

(If you don't provide a handle, STDOUT is the default of course - unless you've asked Perl to use a different default handle...)

Jon Skeet
STDOUT is only the default if you have not used select to tell Perl a different handle should be the default. It is the default default if you will.
Chas. Owens
Thanks Chas - have edited answer.
Jon Skeet
You forgot the semi-colons, this isn't python.
MkV
Thanks semi-colons duly added.
Jon Skeet
+3  A: 

Unless you have said something like 2>&1 on the commandline, STDERR should show up on the screen. You can write to STDERR like Jon Skeet suggests or you can use the warn function.

Chas. Owens