What I Learned about Perl Today

Today I ran into an issue where I needed to redirect STDERR to STDOUT in a Perl script. So, I figured the easiest way would be to redirect those two files somehow. Perl provides a relatively elegant way to do so. Running open(STDERR, ‘>&STDOUT’) will do the trick by overwriting the STDERR filehandle with a duplicate of the STDOUT filehandle in writing mode. In the Perl open documentation, the examples show the programmer saving the previous STDERR filehandle and restoring it at the end of the interactions, but I didn’t require any such thing because the script ends after execution.

Leave a Reply

Your email address will not be published. Required fields are marked *