Don't ask to ask, just ask | |
PerlMonks |
Re^3: why am I getting odd behavior on DESTROYby einhverfr (Friar) |
on Mar 23, 2015 at 10:26 UTC ( [id://1120957]=note: print w/replies, xml ) | Need Help?? |
As a quick write-up as to why this happens and why use strict helps here: The destructor reassigns the garbage-collected object to a global package variable, whichof course cancels the destruction. The next one gets copied over the existing package variable, which of course throws the first object back into garbage collection, which gets copied over the package variable, etc. in a loop. What is suprising here si that Perl doesn't go into an endless loop. Naturally this is hard to debug using standard tools because it is not a misnamed variable but a side effect of a scoping error. Strict prevents this sort of error. Again, anyone wants to use it for presentations or anything regarding why strict, feel free.
In Section
Seekers of Perl Wisdom
|
|