sub find_by_ktag_name { my(@pile) = shift(@_); # start out the to-do stack for the traverser Carp::croak "find_by_created_tag_name can be called only as an object method" unless ref $pile[0]; return() unless @_; print "pile is @pile\n"; my(@tags) = $pile[0]->_fold_case(@_); print "tags are @tags\n"; my(@matching, $this, $this_tag); while(@pile) { $this_tag = ($this = shift @pile)->{'_tag'}; print "In while loop. this_tag is $this_tag\n"; foreach my $t (@tags) { print "foreach going through elements of tag. Elements are t and t is $t\n"; print "next step will check to see if t is eq to this_tag. this_tag is $this_tag\n"; if($t eq $this_tag) { print "inside of if... t and this_tag are equal.\n"; if(wantarray) { print "I am here if wantarray is true. Now push this onto array matching\n"; push @matching, $this; print "matching is @matching\n"; last; } else { print "wantarray not true, returning this $this\n"; return $this; } } } unshift @pile, grep ref($_), @{$this->{'_content'} || next}; } print "returning @matching if wantarray\n"; return @matching if wantarray; return; }