in reply to Re: Parsing newick trees
in thread Parsing newick trees
and then recurse on $left and $right? (Maybe searching each time for the parentheses is as hard as substr'ing, though.)$in = s/^\((.*)\)$/$1/; my @splat = split(/,/, $in); my ( $depth, $left ); while ( my $c = shift @splat ) { $left .= ( $left ? ',' : '' ) . $c; ++$depth if index($c, '(') >= $[; --$depth if index($c, ')') >= $[; last if $depth == 0; } my $right = join(',', @splat);
UPDATE: Per BrowserUK's response, the answer seems to be “Yes, but why?” I always thought that substr's were very expensive, but apparently not. Hurrah for premature optimisation!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parsing newick trees
by BrowserUk (Patriarch) on Oct 17, 2008 at 21:52 UTC |