On Wed, Jan 26, 2011 at 5:46 PM, Ed Avis <eda@waniasset.com> wrote: > This oddity leads to an example Readonly changing the semantics of a program: > > my $b = "abc100"; > $a = "abc100"; 0 + $b; $c = $b; $a ++; $c++; print $c; > > produces '1', whereas > > use Readonly; > Readonly my $b => "abc100"; > $a = "abc100"; 0 + $b; $c = $b; $a ++; $c++; print $c; > > produces 'abc101'. > > That must count as a bug either in Readonly or in perl. Either $b is modified > or it is not. If it is not modified, then marking it readonly should make no > difference. If it is modified, then the Readonly version should fail with a > run time or compile time error at the point where modification is attempted. I can explain that one for you. Readonly uses ties (and most of the time it does so even then Readonly::XS is installed). Under the hood tie reassigns the value to $b on every read, so the effects of 0 + $b gets annihilated. Readonly has many surprising edge cases, and its RT queue contains a good overview of various bugs and issues with ties in perl. LeonThread Previous | Thread Next