I'm sorry, I think that I've given offence. None was 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.
The $class, you mean? Yes, that was a silly think-o—sorry. It seems to compile fine with the obvious modification, though.

My point really was just that throwing a maliciously tied variable at your implementation could break it (a non-point, now that I see that the same is true of local), and I was looking for code that was completely oblivious to the actual variable it was localising.

Did you get such an error from Perl when running my code?
Yes, I did, running perl 5.8.9 installed on a Mac via MacPorts. It also makes sense to me by visual inspection (although you are rightly sceptical of my ability to execute code by looking at it): tie my $x, 'Tie', 1 will leave $x tied to \1, and de-referencing that will lead to an assignment like 1 = 2.
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.
Yes, you are right that I am wrong! :-) I assumed that it would destroy tiedness, but (wrongly) didn't test it. What I was thinking—and this is true—is that tied variables don't always survive round trips, in the sense that my $temp = $x; $x = $temp need not leave the value of $x unchanged. (Perhaps a condition on a reasonable implementation of a tied variable is that that doesn't happen, but I think it's true of a lot of existing classes do not satisfy this condition.)
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)
This is not true on my Perl:
sub TIESCALAR { bless \my $o => $_[0] } sub FETCH { print "Tied\n" } sub STORE {} tie our $x => 'main'; { local $x; $x; # => Tied }
What does ‘work’ (for my definition of working!) is going the other way:
our $x; { local $x; tie $x => 'main'; } $x; # nothing (except a warning about void context)

In reply to Re^6: Local for lexicals (untie) by JadeNB
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.