summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorTassilo von Parseval <tassilo.parseval@post.rwth-aachen.de>2003-12-06 12:50:59 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-06 19:50:07 +0000
commita3bcc51ebd4e201d85a37d8410b7a375b8d94244 (patch)
tree57797ca6128a5011622a6e805fb66f6d2a0fbaa5 /hv.c
parent5c98da1c029548d157089bc95672bf854902dd76 (diff)
downloadperl-a3bcc51ebd4e201d85a37d8410b7a375b8d94244.tar.gz
SCALAR/FIRSTKEY for tied hashes in scalar context
Message-id: <20031206105059.GA13989@ethan> p4raw-id: //depot/perl@21855
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/hv.c b/hv.c
index 39684b0808..ec616c0518 100644
--- a/hv.c
+++ b/hv.c
@@ -786,6 +786,35 @@ S_hv_magic_check(pTHX_ HV *hv, bool *needs_copy, bool *needs_store)
}
/*
+=for apidoc hv_scalar
+
+Evaluates the hash in scalar context and returns the result. Handles magic when the hash is tied.
+
+=cut
+*/
+
+SV *
+Perl_hv_scalar(pTHX_ HV *hv)
+{
+ MAGIC *mg;
+ SV *sv;
+
+ if ((SvRMAGICAL(hv) && (mg = mg_find((SV*)hv, PERL_MAGIC_tied)))) {
+ sv = magic_scalarpack(hv, mg);
+ return sv;
+ }
+
+ sv = sv_newmortal();
+ if (HvFILL((HV*)hv))
+ Perl_sv_setpvf(aTHX_ sv, "%ld/%ld",
+ (long)HvFILL(hv), (long)HvMAX(hv) + 1);
+ else
+ sv_setiv(sv, 0);
+
+ return sv;
+}
+
+/*
=for apidoc hv_delete
Deletes a key/value pair in the hash. The value SV is removed from the