[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: uninitialized vs. undefined



On Sat, 15 Jan 2000 11:12:46 -0800, Gurusamy Sarathy wrote (in part):

>> Shouldn't we use 'exists(&fun)' instead of 'defined(&fun)'
>> then?

gsar> Spider and I had a brief chat about this.  He's working on
gsar> a patch for consideration, I believe.

Yes, but I still can't find the old discussion of the proposed
feature in the archives.  I found plenty of references to it as
something already discussed, but not the original discussion
itself.  So, for those who have been proponents of the feature,
can you remind me (at least) why you want it?  What need does it
fill?  It's trivial to add (preliminary patch without docs
below), but should we?

	--s.

[Apply with `patch -p1'.  This was done atop a patched 5.5.63, so your
line numbers may vary.]

--- ./op.c.GSAR	Sat Jan 15 19:51:56 2000
+++ ./op.c	Sun Jan 16 00:25:43 2000
@@ -1691,7 +1691,7 @@ Perl_ref(pTHX_ OP *o, I32 type)
 
     switch (o->op_type) {
     case OP_ENTERSUB:
-	if ((type == OP_DEFINED || type == OP_LOCK) &&
+	if ((type == OP_EXISTS || type == OP_DEFINED || type == OP_LOCK) &&
 	    !(o->op_flags & OPf_STACKED)) {
 	    o->op_type = OP_RV2CV;             /* entersub => rv2cv */
 	    o->op_ppaddr = PL_ppaddr[OP_RV2CV];
@@ -5033,7 +5033,14 @@ Perl_ck_exists(pTHX_ OP *o)
     o = ck_fun(o);
     if (o->op_flags & OPf_KIDS) {
 	OP *kid = cUNOPo->op_first;
-	if (kid->op_type == OP_AELEM)
+	if (kid->op_type == OP_ENTERSUB) {
+	    (void) ref(kid, o->op_type);
+	    if (kid->op_type != OP_RV2CV)
+		Perl_croak(aTHX_ "%s argument is not a subroutine name",
+			   PL_op_desc[o->op_type]);
+	    o->op_flags |= OPf_STACKED;
+	}
+	else if (kid->op_type == OP_AELEM)
 	    o->op_flags |= OPf_SPECIAL;
 	else if (kid->op_type != OP_HELEM)
 	    Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element",
--- ./pp.c.GSAR	Sat Jan 15 19:51:58 2000
+++ ./pp.c	Sun Jan 16 00:48:06 2000
@@ -2701,8 +2701,22 @@ PP(pp_delete)
 PP(pp_exists)
 {
     djSP;
-    SV *tmpsv = POPs;
-    HV *hv = (HV*)POPs;
+    SV *tmpsv;
+    HV *hv;
+
+    if (PL_op->op_flags & OPf_STACKED) {
+	GV *gv;
+	CV *cv;
+	SV *sv = POPs;
+	cv = sv_2cv(sv, &hv, &gv, FALSE);
+	if (cv)
+	    RETPUSHYES;
+	if (gv && isGV(gv) && GvCV(gv))
+	    RETPUSHYES;
+	RETPUSHNO;
+    }
+    tmpsv = POPs;
+    hv = (HV*)POPs;
     if (SvTYPE(hv) == SVt_PVHV) {
 	if (hv_exists_ent(hv, tmpsv, 0))
 	    RETPUSHYES;


References to:
Gurusamy Sarathy <gsar@ActiveState.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]