Because when you open a in handler it opens file and assigns to it descriptor with first available number -- 2 (STDERR).
Update: try this:
#!/usr/bin/perl use strict; use warnings; close STDERR; open FH, '>', 'log'; die "exit from program\n";
Update2: or more correct method:
#!/usr/bin/perl use strict; use warnings; use POSIX qw(dup2); open FH, '>', 'log'; dup2(fileno FH, 2); die "exit from program\n";
But actually I prefer using Log::Log4perl and its logdie method.
Update3: uhm, I just discovered, that when you open STDERR perl always assigns it to descriptor 2:
#!/usr/bin/perl use strict; use warnings; use POSIX qw(dup2); open FH, '>', 'log'; dup2(fileno FH, 2); open STDERR, '>', 'stderr'; # this would be placed into 'stderr', not into 'log' warn "STDERR descriptor is:", fileno(STDERR), "\n"; die "exit from program\n";
In reply to Re: Log message in Die handler
by zwon
in thread Log message in Die handler
by lakshmananindia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |