Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Experimental warnings with given/when

by Bod (Curate)
on Dec 01, 2020 at 11:13 UTC ( #11124450=note: print w/replies, xml ) Need Help??


in reply to Re: Experimental warnings with given/when
in thread Experimental warnings with given/when

Second, I don't know why the warnings aren't going to where ever STDERR is being redirected to.

I was very curious to understand where Perl sends warning which is why I redirected STDERR. This is not something I do often, hence the deliberate division by zero runtime error to prove that it really was redirected.

# STDOUT given is experimental at test.pl line 17. when is experimental at test.pl line 18. # STDERR Illegal division by zero at test.pl line 22.

So it seems that warnings are sent to STDOUT

Replies are listed 'Best First'.
Re^3: Experimental warnings with given/when
by hippo (Bishop) on Dec 01, 2020 at 11:37 UTC

    Are you sure? With perl 5.20.3:

    $ perl -wE 'given (1) {2}' given is experimental at -e line 1. Useless use of a constant (2) in void context at -e line 1. $ perl -wE 'given (1) {2}' 2> /tmp/err $ cat /tmp/err given is experimental at -e line 1. Useless use of a constant (2) in void context at -e line 1. $

    🦛

      Are you sure?

      I thought I was but I set up a little test to make sure I was sure and now I am not...

      use feature "switch"; # Redirect STDERR open my $err_fh, '>', 'stderr.log'; *STDERR = $err_fh; # Redirect STDERR open my $out_fh, '>', 'stdout.log'; *STDOUT = $out_fh; my $i; given($i) { print "$i\n" when $i < 4; } # Prove STDERR is redirected my $error = 10 / 0;

      Illegal division by zero at test.pl line 15. is the only thing that is written to STDERR and 3 gets written to STDOUT but the following still gets displayed on the command prompt:

      C:\Users\ian\Perl>perl test.pl given is experimental at test.pl line 10. when is experimental at test.pl line 11. C:\Users\ian\Perl>

      So I am not really sure what is going on with output streams as the warnings are on neither STDERR nor STDOUT.

      This is using Perl v5.28.1

        the following still gets displayed on the command prompt

        Those are compile-time warnings. They are generated before your run-time massaging of STDOUT and STDERR have taken effect. In contrast, I used the calling shell to set up the redirection so it is clear there that these warnings go to STDERR.


        🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124450]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-05-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?