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

Hey guys! I keep getting the following compile errors
Use of uninitialized value in string ne at /usr/local/share/perl/5.10. +1/Tree/Nary.pm line 1050. Use of uninitialized value in string ne at /usr/local/share/perl/5.10. +1/Tree/Nary.pm line 1050. Use of uninitialized value in string ne at /usr/local/share/perl/5.10. +1/Tree/Nary.pm line 1050. Use of uninitialized value in string ne at /usr/local/share/perl/5.10. +1/Tree/Nary.pm line 1050.
when I try running the following code using the Tree::Nary module.
#!/usr/bin/perl -w use Tree::Nary; use strict; my $testtree = Tree::Nary->new; my $nodeone = $testtree->insert_data($testtree,1); my $nodetwo = $testtree->insert_data($nodeone,2); my $nodethree = $testtree->insert_data($nodetwo,3); my $foundnode = $testtree->find($testtree,$Tree::Nary::PRE_ORDER,$Tree +::Nary::TRAVERSE_ALL,3);
Sorry if I'm making a super-newbie mistake. Any ideas?
I'm running ubuntu with perl v5.10.1

Thanks!
sagervai

Replies are listed 'Best First'.
Re: Tree::Nary Question
by BrowserUk (Patriarch) on Mar 08, 2011 at 19:17 UTC

    The insert_data() method takes 3 arguments:

    $inserted_node = $node->insert_data($parent, $position, $data);

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Tree::Nary Question
by toolic (Bishop) on Mar 08, 2011 at 19:38 UTC
    BrowserUk has shown us what the problem is.

    I have a few other observations:

    • Those messages are warnings, not errors, which means that your code continues to execute despite problems.
    • It is good that you globally enabled warnings using -w because Tree::Nary does not have use warnings; in its .pm file (a bad thing).
    • Tree::Nary methods perform no input validation (also a bad thing).
      Yeah, it was a total n00b mistake. Thanks guys!
      It should perform validation to catching things that are not errors? What?

        Tree::Nary is not checking that the information being passed to it is both valid and not dangerous to run.

        While I'm not familiar with this module, it's always good to have the information being passed on to be checked for taint and validity.

Re: Tree::Nary Question
by jellisii2 (Hermit) on Mar 11, 2011 at 13:28 UTC
    According to CPAN, the insert_data method takes 3 args.

    insert_data( PARENT, POSITION, DATA ) Inserts a new node containing DATA, beneath the PARENT at the given POSITION. Returns the new inserted node.

    There's no indication that any of them are optional. Is this the case?