From: Gisle Aas Date: Mon, 6 Jul 1998 21:41:14 +0000 (+0200) Subject: Evaluation of AVHVs in scalar context X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4b154ab5f602806ac0f12a58e6d35daf8689fea5;p=p5sagit%2Fp5-mst-13.2.git Evaluation of AVHVs in scalar context Message-ID: p4raw-id: //depot/perl@1358 --- diff --git a/pp_hot.c b/pp_hot.c index 8e3bf70..d825e64 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -544,7 +544,8 @@ PP(pp_rv2hv) } else { dTARGET; - /* This bit is OK even when hv is really an AV */ + if (SvTYPE(hv) == SVt_PVAV) + hv = avhv_keys((AV*)hv); if (HvFILL(hv)) sv_setpvf(TARG, "%ld/%ld", (long)HvFILL(hv), (long)HvMAX(hv) + 1); diff --git a/t/op/avhv.t b/t/op/avhv.t index e01201e..272d222 100755 --- a/t/op/avhv.t +++ b/t/op/avhv.t @@ -17,7 +17,7 @@ sub STORESIZE { $#{$_[0]} = $_[1]+1 } package main; -print "1..6\n"; +print "1..10\n"; $sch = { 'abc' => 1, @@ -78,3 +78,21 @@ if ($a->{'abc'} eq 'ABC') {print "ok 5\n";} else {print "not ok 5\n";} my $slice = join('', 'x',@$a{'abc','def'},'x'); print "not " if $slice ne 'xABCx'; print "ok 6\n"; + +# evaluation in scalar context +my $avhv = [{}]; +print "not " if %$avhv; +print "ok 7\n"; + +push @$avhv, "a"; +print "not " if %$avhv; +print "ok 8\n"; + +$avhv = []; +eval { $a = %$avhv }; +print "not " unless $@ and $@ =~ /^Can't coerce array into hash/; +print "ok 9\n"; + +$avhv = [{foo=>1, bar=>2}]; +print "not " unless %$avhv =~ m,^\d+/\d+,; +print "ok 10\n";