Hi,

This cowde below tries to convert
the string in newick format into the corresponding
data structure (Array of Array).

But somehow the EVAL function doesn't work
as expected. What's wrong with my code here?

__BEGIN__
use Data::Dumper;
use Carp;

my $str = "(foo,(bar,qux))"; #Newick format
print "$str\n";

my $ar = conv_newick2aoa($str);
print Dumper $ar ;

sub conv_newick2aoa {

    my $nstr_in = shift;
    my $nstr    = $nstr_in;
    for ($nstr) {
        s/\\/\\\\/g;
        s/'/\\'/g;
        s/\(/['/g;
        s/\)/']/g;
        s/,/','/g;
    }

    return eval{$nstr};
}
__END__

Why it doesn't give this output instead:

$VAR1 = [
          'foo',
          [
            'bar',
            'qux'
          ]
        ];


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to