in reply to redirect STDERR to my log file, also funny *FOO notation.

Another way to do what you want is to localize STDERR in the scope where you want logging. The trick there is to organize your code so that where you want logging coincides with a scope.

{ open local(*STDERR), '>> /var/log/mylog.log' or die 'Gah! ', $!; # or die 'Gah! ', $/; # Oops, typo # do stuff }

Update: Localizing STDERR does two things.

  1. It confines the new global STDERR handle to the dynamic scope. The old one is automatically restored when the scope is exited. That is the reason for the enclosing curly brackets, to create a scope.
  2. It shares the new temporary STDERR seamlessly. Functions called within the dynamic scope will magically honor logging of STDERR without any need to anticipate it in their definitions.
As I suggested, the trick is to isolate the code you want to log, and only that code, in the scope.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: redirect STDERR to my log file, also funny *FOO notation.
by JohnMG (Beadle) on Nov 15, 2005 at 15:42 UTC
    Why not just
    open STDERR, '>> /var/log/mylog.log'
    instead of
    open local(*STDERR), '>> /var/log/mylog.log'
    ?

    Wait a sec... why did you sneak that $/ in (input record separator) at the end of the call to die()?