From: Rafael Garcia-Suarez Date: Tue, 24 Mar 2009 10:37:35 +0000 (+0100) Subject: Make []~~\&f and {}~~\&f match X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07edf4976478e131431ffbf2f9637678422be875;p=p5sagit%2Fp5-mst-13.2.git Make []~~\&f and {}~~\&f match (Zefram remarks that all(empty set) is true) --- diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index a51a67d..8dfe75c 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -688,8 +688,8 @@ entries apply in those cases. Any CodeRef scalar sub truth $b->($a) Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b] - Array Hash hash slice existence[1] @$a == grep $_ ~~ $b, @$a - Regex Hash hash key grep[1] grep /$a/, keys %$b + Array Hash hash slice existence @$a == grep $_ ~~ $b, @$a + Regex Hash hash key grep grep /$a/, keys %$b undef Hash always false (undef can't be a key) Any Hash hash entry existence exists $b->{$a} @@ -710,7 +710,7 @@ entries apply in those cases. Any Any string equality $a eq $b - 1 - empty hashes or array won't match. + 1 - empty hashes or arrays will match. 2 - that is, each element matches the element of same index in the other array. [3] 3 - If a circular reference is found, we fall back to referential equality. diff --git a/pp_ctl.c b/pp_ctl.c index 8908850..a8a3610 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -4072,7 +4072,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) HV *hv = (HV*) SvRV(d); I32 numkeys = hv_iterinit(hv); if (numkeys == 0) - RETPUSHNO; + RETPUSHYES; while ( (he = hv_iternext(hv)) ) { ENTER; SAVETMPS; @@ -4100,7 +4100,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) AV *av = (AV*) SvRV(d); const I32 len = av_len(av); if (len == -1) - RETPUSHNO; + RETPUSHYES; for (i = 0; i <= len; ++i) { SV * const * const svp = av_fetch(av, i, FALSE); ENTER; diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index ce02c00..6993c2e 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -192,8 +192,8 @@ __DATA__ ! [1] \&foo ! {a=>1} \&foo # empty stuff matches, because the sub is never called: -! [] \&foo -! {} \&foo + [] \&foo + {} \&foo ! qr// \&foo ! undef \&foo undef \&bar @@ -204,8 +204,8 @@ __DATA__ @ "foo" \&fatal @ qr// \&fatal # sub is not called on empty hashes / arrays -! [] \&fatal -! +{} \&fatal + [] \&fatal + +{} \&fatal # HASH ref against: # - another hash ref