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

How would I get each $child->id into an array and then return the 2nd element in the array?
#Read in Tree use Bio::TreeIO; my $treeio = Bio::TreeIO->new(-format => 'newick',-file => $filename); my $tree = $treeio->next_tree; #You can find the species of interest ‘x' foreach my $id(@lines){ my $node = $tree->find_node(-id => $id); #Find internal node that is its immediate ancestor my $ancestral_node = $node->ancestor(); #Find all descendants from ancestor (which will include ‘x’) for my $child ( $ancestral_node->get_all_Descendents ) { print $child->id, "\n"; } }

Replies are listed 'Best First'.
Re: Return second element
by choroba (Cardinal) on Jul 09, 2017 at 21:09 UTC
    Checking the documentation of the method get_all_Descendents , it shows:
    my @taxa = $db->get_all_Descendents($taxon);

    The second element of an array is under index 1:

    print $taxa[1], "\n";

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Return second element
by hippo (Archbishop) on Jul 09, 2017 at 21:09 UTC
    How would I get each $child->id into an array

    With push or unshift or map. What did you try? How did it fail?

    and then return the 2nd element in the array?

    Seriously? Start with perlintro - it's right in there.