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

In reply to Re^11: Merge 2 lines in 1 die statement by blazar
in thread Die statement with text & formatting of the user by Nik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.