Hi group,

 

My Unicode blues continues… One more question on handling Unicode.

 

Does Tree::Nary module works with Unicode data? I am trying to store some 
Unicode strings (UTF-8 to be precise) as Nary Tree.

 

When I retrieve the value of the nodes from the tree, it produces the output as 
boxes, even though I am using binmode for activating the utf-8 layer and am 
reasonable sure that I am not making any mistakes. I should also mention that, 
the same code works well with normal data (such as English strings) Anyway, 
here is the code:

 

Thanks in advance.

 

-B

 

---

 

The file ‘temp1.txt’ will have this sequence: पढ़ते है . राम पुस्तक एक

 

 

use Tree::Nary;

use warnings;

 

open(O, ">children.txt");

binmode (O, ":utf8");

 

open(I, "<utf8", "temp1.txt");

while(<I>) {

            chomp;

            @words = split(/\s+/, $_);

}

close(I);

 

$root = Tree::Nary->new($words[0]);

$node = Tree::Nary->new();

 

$node101 = $node->insert_data($root, 1, $words[1]);

$node102 = $node->append_data($root, $words[2]);

 

$node103 = $node->prepend_data($root, $words[3]);

$node231 = $node->insert_data($node103, 1, $words[4]);

$node232 = $node->prepend_data($node103, $words[5]);

 

undef $elements;

$node->traverse($root, $Tree::Nary::PRE_ORDER, $Tree::Nary::TRAVERSE_ALL, -1, 
\&building_node);

print O "Elements of the Tree : $elements\n";

 

$total_nodes = $node->n_nodes($root, $Tree::Nary::TRAVERSE_ALL);

print O "The tree has $total_nodes nodes in total\n";

 

close(O);

 

sub building_node() {

            my $node = shift;

            my $child = $node->{data};

            if(!defined $elements) { $elements .= $child; }

            else { $elements .= " ".$child; }

 

            return ($Tree::Nary::FALSE);

}

Reply via email to