This may be a familiar territory for the gurus.. When we 'delete' an
object, Perl does not. Because it is difficult to explain, I am giving
the code snippets below... Mike (a.k.a netgeek) thinks we need to use
'tie'. I am not certain we understand the problem here..
I have a module that creates XML as nodes in a tree structure. Each node
is a hashref that looks like..
{
tag_name=>'something',
attrib=>{},
content=>[.... Hash references of children nodes...]
}
We implemented an module to manipulate the tree - to add, delete,
access etc.
my $node = new Object;
$root = $node->add_element('root');
$child = $root->add_element('child');
.....
$child->delete_element();
print
"<?xml version=\"1.0\" ?>",
$node->to_string(); # strangely it prints the child
node too!
Here are some snippets.. The problem is that "delete" does not delete
the object. Looks like there is some other reference lurking
somewhere!
new method ...
return bless {
path => $tree->[0] # where tree was simply my $tree;
}, $class;
add_element method does:
sub add_element {
my ($self,$name) = @_;
my $e = {
tag_name=>$name,
attrib=>{},
content=>[],
};
if (exists $self->{path}{tag_name}) { # all subsequent adds down the
tree
push @{$self->{path}{content}},$e;
return bless { # is the problem the way
we create the element?
path =>
$self->{path}{content}[(scalar(@{$self->{path}{content}})-1)]
}, $class;
} else { # empty, so create as root # for the first
add ...
push @$tree,$e;
$self->{path} = $tree->[(scalar(@$tree)-1)];
return bless {
path => $tree->[(scalar(@{$tree})-1)]
}, $class;
}
}
delete_element method does:
sub delete_element {
my ($self) = @_;
delete $self->{path}; # what is
happpening here?
$self = undef;
return;
}
Thanks for any pointers...
---Closing information gaps-----
Ranga Nathan, Reliance Technology
>>SEVIS solution now! http://goreliance.com
>>Live demo at http://any2xml.com/docs/timesheet_demo.shtml<<
>>Get free COBOLExplorer at http://goreliance.com/download-products <<
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm