Friday, March 15, 2013

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.

No comments:

Post a Comment