Re: lost node at /usr/lib/perl5/XML/LibXML.pm line 1205.
"Jenda Krynicky" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
From: "Jonas Häggqvist" <[email protected]> > I'm getting a strange error when doing getElementsByTagName() on a > Document. Admittedly it could be related to my sub-par Perl-fu, but it > seems like I should at least not get a segfault it things were working > correctly. > > The minimal example below shows this behaviour. > > $ cat temp.pl > #!/usr/bin/perl > > use XML::LibXML; > > sub readfile { > my ($file) = @_; > $doc = XML::LibXML->new->parse_file($file); > return \($doc); > } > > my ($doc) = readfile($ARGV[0]); > bless($doc, 'XML::LibXML::Document'); You should not bless() references outside the new() subroutine of your own classes unless you really know you must and why. In this case you should have looked at the $doc and you'd see that it's an unblessed scalar reference. And wonder why. The reason is the return \($doc); namely the \(). This "operator" creates references to all its operands. That is \( $foo, $bar, @baz, %bat) is equivalent to ( \$foo, \$bar, \@baz, \%bat) so in your case your readfile() subroutine returns a reference to the object, not the object itself (the fact that an object is just a blessed reference just confuses the issue, what you ended up was a reference to a reference). Just drop the backslash and the bless(). HTH, Jenda ===== [email protected] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs