From 4b154ab5f602806ac0f12a58e6d35daf8689fea5 Mon Sep 17 00:00:00 2001 From: Gisle Aas Date: Mon, 6 Jul 1998 23:41:14 +0200 Subject: [PATCH] Evaluation of AVHVs in scalar context Message-ID: p4raw-id: //depot/perl@1358 --- pp_hot.c | 3 ++- t/op/avhv.t | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) 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"; -- 2.7.4