Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Experimental warnings with given/when

by LanX (Saint)
on Dec 01, 2020 at 00:22 UTC ( [id://11124434]=note: print w/replies, xml ) Need Help??


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

> 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

Replies are listed 'Best First'.
Re^4: Experimental warnings with given/when
by tobyink (Canon) on Dec 02, 2020 at 01:18 UTC

    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.

Re^4: Experimental warnings with given/when
by ikegami (Patriarch) on Dec 01, 2020 at 08:37 UTC

    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found