bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to understand the relevance of this line:#!/usr/bin/perl use strict; use Data::Dumper; my $root; insert( $root, 5 ); insert( $root, 3 ); print Dumper \$root; sub insert { my ($tree, $value) = @_; unless ($tree) { $tree = {}; $tree->{VALUE} = $value; $tree->{LEFT} = undef; $tree->{RIGHT} = undef; $_[0] = $tree; # $_[0] is reference param! return; } if ( $tree->{VALUE} > $value ) { insert( $tree->{LEFT}, $value ) } elsif ( $tree->{VALUE} < $value ) { insert( $tree->{RIGHT}, $value + ) }; }
He mentioned that this is a reference param. And also he mentioned that "The assignment of the new node back to $_[0] alters the value in its caller."$_[0] = $tree;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Binary Search Tree Debug Question
by jdporter (Paladin) on Aug 12, 2011 at 18:29 UTC | |
Re: Binary Search Tree Debug Question
by Perlbotics (Archbishop) on Aug 12, 2011 at 18:19 UTC | |
Re: Binary Search Tree Debug Question
by FunkyMonk (Chancellor) on Aug 13, 2011 at 13:56 UTC | |
Re: Binary Search Tree Debug Question
by Anonymous Monk on Aug 12, 2011 at 19:19 UTC | |
by Tanktalus (Canon) on Aug 12, 2011 at 19:36 UTC |