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

hello,

Got a problem I don't find a solution too.

See Following code example:
sub init_parse { my $self = shift; my $root = $self->{'DOC'}->getDocumentElement(); print "$root\n"; &traverse($root); } sub traverse { my $node = @_; print "DEBUG: $node\n"; }
The output is following:
XML::LibXML::Element=SCALAR(0x1e104c) DEBUG: 1
I know it's a reference, but I want to pass it too te next subroutine in my module. But it doesn't work. It's probably something obvious I'm looking over. My perl module writing skills are not that advanced :)


--
My opinions may have changed,
but not the fact that I am right

Replies are listed 'Best First'.
Re: references and modules
by bwana147 (Pilgrim) on Jul 23, 2001 at 13:13 UTC

    my $node = @_;

    $root is a scalar, so you evaluate @_ in scalar context, which yields the number of elements in @_, not its first element.

    Here are a couple of ways of doing it:

    my $node = shift; my $node = $_[0]; my ($node) = @_;

    UPDATE: D'oh! I wrote my whole reply with $root whereas the problem is with $node. Fixed this.

    --bwana147

Re: references and modules
by Cybercosis (Monk) on Jul 23, 2001 at 13:15 UTC
    Your problem is with the my $node = @_;. What is happening is that you're telling perl to interpret @_ as a scalar, which will give you the number of elements in the list (1, in this case). To force list context, do this: my($node) = @_;

    ~Cybercosis

    nemo accipere quod non merere