Problem with Eval in Constructing AoA

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


This code 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?

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) {

    return eval;

Why it doesn't give this output instead:

$VAR1 = [

Gundala Viswanath

Re: Problem with Eval in Constructing AoA

Quoted text here. Click to load it

This probably isn't doing what you think. Here you try to evaluate the
block consisting on the literal code '$nstr', which of course
evaluates to the value of the variable $nstr.

What you want to is to evaluate the value of $nstr itself. That is

    return eval $nstr.

... but in you example $nstr doesn't consist of valid perlcode.


Site Timeline