in reply to Re^9: Merge 2 lines in 1 die statement
in thread Die statement with text & formatting of the user

I still miss the reason of WHY although i'am redirecting all error to the new standard output which after the above code is the computer screen, i still i get both my print statememnt printed and another error as well. Why does die print 2 errors in this case?
  • Comment on Re^10: Merge 2 lines in 1 die statement

Replies are listed 'Best First'.
Re^11: Merge 2 lines in 1 die statement
by ikegami (Patriarch) on Apr 29, 2007 at 05:35 UTC
    It seems that a lot of your questions are of the form "Why does X do Y?" when X doesn't do Y. die doesn't print two errors messages unless you give it to error messages to print.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^11: Merge 2 lines in 1 die statement
by blazar (Canon) on Apr 29, 2007 at 12:17 UTC
    I still miss the reason of WHY although i'am redirecting all error to the new standard output which after the above code is the computer screen, i still i get both my print statememnt printed and another error as well. Why does die print 2 errors in this case?

    I think you're still missing what die really does. To quote from the docs: "Outside an "eval", prints the value of LIST to "STDERR" and exits with the current value of $! (errno)." Note that the emphasis is mine: then the document goes at some length into explaining that things are not really that simple. But the point is that die exits with a value that indicates an error, independently of what gets printed to where. These are orthogonal consequences. See the following example script:

    #!/usr/bin/perl use strict; use warnings; if (@ARGV) { my $msg="This is printed to STDOUT\n"; { _die => sub () { local *STDERR=*STDOUT; die $msg; }, _print => sub () { print $msg; exit 0; } }->{+shift}->(); } sub chk { my $cmd=shift; my $ret=system $0 => $cmd; warn "Failure to run <$cmd>: $!\n" and return if $ret == -1; warn "<$cmd> died with status: ", $? >> 8, "\n" unless $ret == 0; } chk $_ for qw/_print _die/; __END__

    It gives me:

    This is printed to STDOUT This is printed to STDOUT <_die> died with status: 255