then the given code blows up
I agree that my code isn't a very good implementation of a tied variable, but it is what I meant

Code that doesn't compile (under strict) is what you meant? And it is your STORE that causes things to "blow up". Just to be clear, my code works just fine if given a tied implementation that isn't seriously broken.

Your code doesn't quite fix it, because you try to assign to a read-only variable

I ran my code and got no complaints about assigning to read-only variables. Did you get such an error from Perl when running my code? Or are you determining that a read-only variable is being assigned to based on visual inspection of the code? Or did you plug my code into some other example and get that error? This might be a difference between Perl versions. I just kept your TIESCALAR code as close to what you wrote as I could.

Of course, I could just put my $temp = $x; $x = 2 at the top of the scope and $x = $temp at the end [...] but this isn't completely satisfactory: For example, if $x starts off tied, then it will no longer be after my $temp = $x; $x = $temp.

You are wrong there as well. my $temp= $x; $x= $temp; doesn't leave $x no longer tied.

So I have some doubt of what your real requirements are. Yes, local causes a variable to temporarily not be tied (something that I find mostly to be an accident of implementation choice not something that makes sense as an intentional feature). You state that you want this behavior of local (but don't really explain why) but you also think that my code won't work with a tied variable, when it works just fine and you complain that the lexical variable will end up untied when that doesn't happen.

So I can see wanting code to not "blow up" with "tied variables (probably among other circumstances)". And I can see not wanting the variable to end up untied. But neither of those are problems with my implementation.

If somebody goes out of their way to tie $x before invoking lambda $x => sub { $x**2 }, then I think they would also be surprised to have that tie have no impact each time sub { $x**2 } gets called.

- tye        


In reply to Re^5: Local for lexicals (untie) by tye
in thread Local for lexicals by JadeNB

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.