I've got a really simple object
which works fine until I try to debug it under ptkdb. The call to bless clears the contents of $self and I'm left with an empty, blessed scalar. $page is still intact.
I've heard of variable suicide - it's mentioned in, eg, CGI.pm, but I don't know what causes it, how to avoid it or, indeed, whether that is what I'm seeing.
f
"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
Code:
package Doc::Page;
use strict;
# A page is a scalar containing the page data.
# It can be searched, processed and printed.
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $page = $_[0] ? shift : "";
my $self = \$page;
bless($self, $class);
return($self);
}
which works fine until I try to debug it under ptkdb. The call to bless clears the contents of $self and I'm left with an empty, blessed scalar. $page is still intact.
I've heard of variable suicide - it's mentioned in, eg, CGI.pm, but I don't know what causes it, how to avoid it or, indeed, whether that is what I'm seeing.
f
"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes