summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-12-04 01:00:49 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-12-04 01:00:49 +0000
commit2c8ac474a00b933b4d84e8567b4b6db1293ad0ef (patch)
treee6aae0baa7006e94a6f49152182180b0cd4a5948 /op.c
parent951ba7fe8dad4074b389cb34ee7e8b446c17c0fb (diff)
downloadperl-2c8ac474a00b933b4d84e8567b4b6db1293ad0ef.tar.gz
better implementation of change#3326; open(local $foo,...) now
allowed in addition to any uninitialized variable, for consistency with how autovivification works elsewhere; add code to use the variable name as the name of the handle for simple variables, so that diagnostics report the handle: "... at - line 1, <$foo> line 10." p4raw-link: @3326 on //depot/perl: 853846ea710f8feaed8c98b358bdc8967dd522d2 p4raw-id: //depot/perl@4639
Diffstat (limited to 'op.c')
-rw-r--r--op.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/op.c b/op.c
index 1be2428406..155c001f09 100644
--- a/op.c
+++ b/op.c
@@ -5286,26 +5286,46 @@ Perl_ck_fun(pTHX_ OP *o)
else {
I32 flags = OPf_SPECIAL;
I32 priv = 0;
+ PADOFFSET targ = 0;
+
/* is this op a FH constructor? */
if (is_handle_constructor(o,numargs)) {
- flags = 0;
- /* Set a flag to tell rv2gv to vivify
+ char *name = Nullch;
+ STRLEN len;
+
+ flags = 0;
+ /* Set a flag to tell rv2gv to vivify
* need to "prove" flag does not mean something
* else already - NI-S 1999/05/07
- */
- priv = OPpDEREF;
-#if 0
- /* Helps with open($array[$n],...)
- but is too simplistic - need to do selectively
- */
- mod(kid,type);
-#endif
+ */
+ priv = OPpDEREF;
+ if (kid->op_type == OP_PADSV) {
+ SV **namep = av_fetch(PL_comppad_name,
+ kid->op_targ, 4);
+ if (namep && *namep)
+ name = SvPV(*namep, len);
+ }
+ else if (kid->op_type == OP_RV2SV
+ && kUNOP->op_first->op_type == OP_GV)
+ {
+ GV *gv = cGVOPx_gv(kUNOP->op_first);
+ name = GvNAME(gv);
+ len = GvNAMELEN(gv);
+ }
+ if (name) {
+ SV *namesv;
+ targ = pad_alloc(OP_RV2GV, SVs_PADTMP);
+ namesv = PL_curpad[targ];
+ SvUPGRADE(namesv, SVt_PV);
+ if (*name != '$')
+ sv_setpvn(namesv, "$", 1);
+ sv_catpvn(namesv, name, len);
+ }
}
kid->op_sibling = 0;
kid = newUNOP(OP_RV2GV, flags, scalar(kid));
- if (priv) {
- kid->op_private |= priv;
- }
+ kid->op_targ = targ;
+ kid->op_private |= priv;
}
kid->op_sibling = sibl;
*tokid = kid;