[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[PATCH] perlsyn: equivalent code for HASH ~~ ARRAY




I've adjusted the example in the smart matching table in perlsyn. The
equivalent Perl for smart matching an array and a hash checks that all
of the array elements are keys in the hash, so you have to check that
grep returns the number of input elements, not just at least one
element.


--- perlsyn.pod 2007-12-18 10:47:08.000000000 +0000
+++ perlsyn.pod-new     2008-06-07 10:19:51.000000000 +0100
@@ -674,7 +674,7 @@
     Any     Code[+]   scalar sub truth         $b->($a)
 
     Hash    Hash      hash keys identical      [sort keys %$a]~~[sort
keys %$b]
-    Hash    Array     hash slice existence     grep {exists $a->{$_}}
@$b
+    Hash    Array     hash slice existence     @$b == grep {exists
$a->{$_}} @$b
     Hash    Regex     hash key grep            grep /$b/, keys %$a
     Hash    Any       hash entry existence     exists $a->{$b}


Follow-Ups from:
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]