There are serious flaws with this code.

For example, my @species = split "//", $list;. The @species array will contain each letter of $list (a split on the null string is every letter of the original string).

update: Opps... @species = split(//,$list) is not @species = split("//",$list). A cross-eyed booboo on my part. Sorry.

@tree will contain the lines returned from the "backtick" command in the subroutine. The foreach loop is the main program as presented.

my @tree_array; # my @species = split "//", $list; # would: # foreach my species ('a','b','c') {} work? I think not? foreach my $species(@species) { my @tree = edit($species); push @tree_array, [@tree] if @tree; print @tree if @tree; } ## do you want to use @tree here? ## if so, then ...you need to use the array ## of the @tree results... foreach $tree_ref (@tree_array) { print "@$tree_ref\n"; } sub edit { my ($species) = shift; #slightly faster when just one arg my ($pid) = ($species =~ /RANK.*?subspecies.*?PARENT ID.*?(\d+)/); ### or ### ## look for "PARENT ID", then anything until there are ## one or more digits my ($pid) = ($species =~ /PARENT ID.*?(\d+)/); if (defined $pid) { return `getz "[taxonomy:$pid]" -e`; } return undef; }
Feel free to modify the above code, show a runnable example of your problem.

In reply to Re: local and global variable? by Marshall
in thread local and global variable? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.