Welcome to the Monastery | |
PerlMonks |
Re: Action at a distanceby ikegami (Patriarch) |
on Nov 03, 2022 at 14:41 UTC ( [id://11147948]=note: print w/replies, xml ) | Need Help?? |
Quite the opposite. If anything, it's about the lack of copy on write. $x and $y are references to objects. You are copying the reference, but not the referenced object (on write or otherwise). You want $y = $x->copy(); to create a clone.
To avoid getting bit by this, only uses classes that provide immutable objects. Also, you'll need to avoid references to arrays and hashes, as the same issue is found there.
Even then, you'll have to worry about aliases.
It's a performance concession. Using immutable objects has a high cost. You brought up Perl's COW mechanism for strings. It's specifically a mechanism to mitigate these costs. For strings. Imagine having to build COW into all your classes... And how it would work for classes that reference external (to perl) resources?
In Section
Seekers of Perl Wisdom
|
|