Normally on unix-like systems a process is started with three open file descriptors. STDIN, STDOUT, STDERR. (Think "standard in", "standard out", "standard error".) Each file descriptor has a traditional use.
Programs read from STDIN. Normally this means the program reads from the console but it is often from a pipe.
Programs write the normal output to STDOUT. Normally this means when the program writes to STDOUT it goes to the console but it is often sent to a pipe.
Programs write error related output to STDERR. Again normally this means when the program writes to STDERR it goes to the console but it is often sent to a pipe.
Note that there is no requirement that the programs you write report errors to STDERR but most unix programs do. The reason is someone might throw away STDOUT because they don't actually want to see it but if an error shows up they do want to see it. For example "some_program > /dev/null".
To see the difference run this program:
#!/usr/bin/perl -w
use strict;
print STDOUT "this is stdout\n";
print STDERR "this is stderr\n";
STDOUT is given the number 1 and STDERR the number 2. (STDIN is number 0, ie zero.) These BASH shell commands will show you what happens when you redirect the different files to the junk bin "/dev/null".
$ ./stdout-stderr.pl 1>/dev/null
this is stderr
$ ./stdout-stderr.pl 2>/dev/null
this is stdout
If you are new to unix programming you should have a look at the Unix Programming Frequently Asked Questions.
| [reply] [d/l] [select] |
STDERR is the filehandle name for output to standard error, and the name is special in Perl (see perlvar). STERR is nothing special in Perl, although someone might have used it as the name for a filehandle.
You don't need any code to illustrate the difference because there's no difference to show. :)
Where did you see this and why do you ask?
| [reply] |
You must be using windows, because on linux
#!/usr/bin/perl
use warnings;
use strict;
print STDERR "STDERR oops\n";
print STERR "STERR oops\n";
gives
Name "main::STERR" used only once: possible typo at ./z8a line 7.
STDERR oops
print() on unopened filehandle STERR at ./z8a line 7.
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] [select] |
Same error on my activestate 5.8.1 on win32
| [reply] |
However, the stderr handle is aliased to STDERR for compatibility with older perls.
| [reply] [d/l] [select] |
They are not identical. STDERR is a handle, automatically opened, used to display error messages. I don't find anywhere that STERR is a Perl variable (or an OS variable, either).
The main difference between the two is that STDERR is automatically opened when you start Perl (along with STDIN and STDOUT). You can print to or read from these three handles right away, without having to open them. If you want to use STERR as a handle, you need first to open it.
| [reply] |