in reply to Log message in Die handler
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Log message in Die handler
by gone2015 (Deacon) on Jan 16, 2009 at 13:36 UTC |