develooper Front page | perl.perl5.porters | Postings from June 2008

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

Thread Next
From:
brian d foy
Date:
June 7, 2008 15:59
Subject:
[PATCH] perlsyn: equivalent code for HASH ~~ ARRAY
Message ID:
070620082359221579%brian.d.foy@gmail.com

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}

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About