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
2009-04-14 06:05:37
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
2009-04-14 08:20:57
Thanks Chas - have edited answer.
Jon Skeet
2009-04-14 12:37:47
You forgot the semi-colons, this isn't python.
MkV
2009-04-14 15:42:20
Thanks semi-colons duly added.
Jon Skeet
2009-04-14 16:55:28
+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
2009-04-14 08:19:45