Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Experimental warnings with given/when

by dave_the_m (Monsignor)
on Nov 30, 2020 at 23:56 UTC ( [id://11124430]=note: print w/replies, xml ) Need Help??


in reply to Experimental warnings with given/when

You raise three points. First, the warnings aren't being disabled via 'use experimental "switch";' because you need to enable warnings with 'use warnings' before disabling selected warnings.

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

Third, smartmatch and switch were made retropectively experimental because it was widely agreed that they were broken in concept in many ways, but a consensus has never been reached on how to fix them. But the expectation is that at some point their behaviour may change, possibly radically, or they may be removed altogether.

Dave.

  • Comment on Re: Experimental warnings with given/when

Replies are listed 'Best First'.
Re^2: Experimental warnings with given/when
by GrandFather (Saint) on Dec 01, 2020 at 00:00 UTC

    With my C/C++ (and various other language) background I like given/when a lot. Making smart match a whole lot dumber would pretty much fix the problem in my book, but that's a fairly limited book and it's probably missing important pages.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      > Making smart match a whole lot dumber would pretty much fix the problem in my book

      definitely, many people want an in operator without needing to resort to temporary hash tricks

      DB<19> use experimental 'smartmatch'; say 1 ~~ [1,2,3] 1

      what's stopping them is the huge table of cases.

      "dumbmatch" should be much simpler to understand.

      perlop#Smartmatch-Operator

      Left Right Description and pseudocode =============================================================== Any undef check whether Any is undefined like: !defined Any Any Object invoke ~~ overloading on Object, or die Right operand is an ARRAY: Left Right Description and pseudocode =============================================================== ARRAY1 ARRAY2 recurse on paired elements of ARRAY1 and ARRAY2[2 +] like: (ARRAY1[0] ~~ ARRAY2[0]) && (ARRAY1[1] ~~ ARRAY2[1]) && ... HASH ARRAY any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY Regexp ARRAY any ARRAY elements pattern match Regexp like: grep { /Regexp/ } ARRAY undef ARRAY undef in ARRAY like: grep { !defined } ARRAY Any ARRAY smartmatch each ARRAY element[3] like: grep { Any ~~ $_ } ARRAY Right operand is a HASH: Left Right Description and pseudocode =============================================================== HASH1 HASH2 all same keys in both HASHes like: keys HASH1 == grep { exists HASH2->{$_} } keys HASH1 ARRAY HASH any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY Regexp HASH any HASH keys pattern match Regexp like: grep { /Regexp/ } keys HASH undef HASH always false (undef can't be a key) like: 0 == 1 Any HASH HASH key existence like: exists HASH->{Any} Right operand is CODE: Left Right Description and pseudocode =============================================================== ARRAY CODE sub returns true on all ARRAY elements[1] like: !grep { !CODE->($_) } ARRAY HASH CODE sub returns true on all HASH keys[1] like: !grep { !CODE->($_) } keys HASH Any CODE sub passed Any returns true like: CODE->(Any) Right operand is a Regexp: Left Right Description and pseudocode =============================================================== ARRAY Regexp any ARRAY elements match Regexp like: grep { /Regexp/ } ARRAY HASH Regexp any HASH keys match Regexp like: grep { /Regexp/ } keys HASH Any Regexp pattern match like: Any =~ /Regexp/ Other: Left Right Description and pseudocode =============================================================== Object Any invoke ~~ overloading on Object, or fall back to... Any Num numeric equality like: Any == Num Num nummy[4] numeric equality like: Num == nummy undef Any check whether undefined like: !defined(Any) Any Any string equality like: Any eq Any

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        match::simple is my take on a dumb match.

        Its table is just:

        Left Right Description and pseudocode =============================================================== Any undef check whether Any is undefined like: !defined Any Any non-ref string equality like: Any eq Any Any Regexp pattern match like: Any =~ /Regexp/ Any CODE sub passed Any returns true like: CODE->(Any) Any ARRAY smartmatch each ARRAY element[3] like: grep { Any ~~ $_ } ARRAY Any object call `MATCH` method on Object, or invoke ~~ overloading on Object, or die Any other die

        So the behaviour is predictable based on the right-hand side.

        what's stopping them is the huge table of cases.

        That could very well be part of it, but the main reason (in my mind) is the fact that the table treats two (stored as a number) differently than two (stored as a string). This leads to surprises/problems because the rest of Perl doesn't tend to distinguish how something is stored. This means the operator is broken-by-design.

Re^2: Experimental warnings with given/when
by Bod (Parson) on Dec 01, 2020 at 11:13 UTC

    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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found