loris has asked for the wisdom of the Perl Monks concerning the following question:

Hello Blessed and Blessing Monks,

I want to do something like:

my $node = $self->makeMyNode('Blorp') $self->addMyNode($node); ... sub addMyNode { my ($self,$node) = @_; my $parentNode = $self->generateParentNode($node); $parentNode->addChild($node); }

but I get the error

XML::LibXML::Node::addChild() -- nNode is not a blessed SV reference a +t ...

I assume I must do bless at some point, but I am not clear how. Should I be passing a reference and then blessing that?

Thanks,

loris


"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

Replies are listed 'Best First'.
Re: Unblessed problem when passing structures as agrument
by dragonchild (Archbishop) on Oct 27, 2005 at 13:38 UTC
    Your error message indicates that there's a lot more to the problem than your code snippet is demonstrating. Please provide a complete, but minimal, testcase that I can cut'n'paste and run on my computer, otherwise I'm not sure any of us are going to be much help. Remember - I'm not sitting next to you, so you have to provide enough information for me to replicate your problem.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      Oops, sorry, I thought I was making some fairly elementary Perl blunder that my example would illustrate. It turns out that in fact the function I thought was giving me the parent node was in fact incorrectly returning an integer. Doh.

      I shall look a bit harder myself before posting again next time. Thanks for the interest anyway.

      The Monk with Egg All Over his Face, All Down the Front of His Habit, and Quite a Lot on the Keyboard too


      "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."