develooper Front page | perl.perl5.porters | Postings from May 2004

my $x->{foo} doesn't work

Thread Next
From:
tetryl
Date:
May 20, 2004 20:45
Subject:
my $x->{foo} doesn't work
Message ID:
200405211244.31291.tetryl@tokyoprogrammer.com
Hi all,

I love my variable and am looking for various ways of using it.
I will show you a bit of code.

$ perl -e 'my $x;$x->{foo}'     # OK
$ perl -e '(my $x)->{foo}'      # NG

I expected that autovivification would be applied to the
variable in the later case as well as in the first case, but
the results were different.
Therefore I wrote the following patch.
I would like your responses to that.

--- pp_hot.c.orig       2004-05-21 10:49:37.000000000 +0900
+++ pp_hot.c    2004-05-21 10:50:32.000000000 +0900
@@ -202,13 +202,13 @@
     dSP; dTARGET;
     XPUSHs(TARG);
     if (PL_op->op_flags & OPf_MOD) {
-       if (PL_op->op_private & OPpLVAL_INTRO)
-           SAVECLEARSV(PAD_SVl(PL_op->op_targ));
-        else if (PL_op->op_private & OPpDEREF) {
+        if (PL_op->op_private & OPpDEREF) {
            PUTBACK;
            vivify_ref(PAD_SVl(PL_op->op_targ), PL_op->op_private & OPpDEREF);
            SPAGAIN;
        }
+       else if (PL_op->op_private & OPpLVAL_INTRO)
+           SAVECLEARSV(PAD_SVl(PL_op->op_targ));
     }
     RETURN;
 }

regards

--
Shinya Hayakawa
hayakawa@livedoor.jp

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About