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

But i though local *STDERR = *STDOUT was supposed to redirect all errors to the default output

There. You are giving yourself the answer :-)

That's why the error shows on your "screen" - i.e. the browser. It gets the STDERR because you have redirected it to STDOUT, otherwise it would be directed to the error log.

Don't do that, don't die on line 74, just print the error message, then exit. All will be fine, and because, then, your scripts exits 0, no 500 error page will be generated.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^10: Merge 2 lines in 1 die statement
by Nik (Initiate) on Apr 28, 2007 at 17:10 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?
      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.
      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