Localize the package global first, and then call the lvalue sub.

Thanks for your time but I've confused the issue a little by using a variable accessible from the current scope. I was specifically interested in why the particular corner I've backed myself into doesn't work.
{ my $foo = 1; sub level : lvalue {$foo} } print level(); { local level() = 2; print level(); } print level(); __END__ 122

I read local Foo->level = 2 as trying to localize an expression (the lvalue sub itself?), and not the package global this sub operates on.

Ah that's interesting, after reading your reply I've run B::Deparse on my new example (sans our'd package variables) and the local() is removed altogether:
{ my $foo = 1; sub level : lvalue { $foo; } ; } print level(); { level() = 2; print level(); } print level();


Hmm? $Foo::level is no reference - calling Scalar::Util::refaddr on it yields undef.


I did \ my lvalues first :)

My testing methods may be unorthodox but it seemed like a simple way to asses if the local() had happened like I expected and the localized Scalar::Util::refaddr \$Foo::level; now pointed at a different address.

Presumably because perl has to create a new SV slot on the scratchpad for the inner scope the SV in question will have a different address when localized assuming everything goes well (I think I've got the lingo right?).

Cheers,
Shane.

In reply to Re^2: Localize lvalue subroutine. by shanna
in thread Localize lvalue subroutine. by shanna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.