Hi

after some tweaking I found answer for my question, here is one possible solution, it works only if categories are created from the scratch.
use strict; use warnings; use DBIx::Tree::NestedSet; use DBI; use Data::Dumper; $Data::Dumper::Indent = 1; my $dbh = DBI->connect('DBI:mysql:test','root','') or die ($DBI::errstr); my $tree = DBIx::Tree::NestedSet->new( dbh => $dbh, no_locking => 1, table_name => 'db_tree' ); $dbh->do("DELETE from db_tree"); #we can't have more "top" categories, so we create "main" $tree->add_child_to_right( name=>'main' ); my %tree = (); while (<DATA>) { chomp; my $hr; $hr->{last_node_id} = 0; my $t = \%tree; for my $item ( split '/' ) { #if path doesn't exists in hash unless ( exists $t->{$item} ) { #add to db $hr->{last_id} = $tree->add_child_to_right( name => $item, id=>$hr->{last_node_id} ); #make data hash structure $t->{$item} = { 'node_id' => $hr->{last_id} } ; } $hr->{last_node_id} = $t->{$item}{node_id}; print $hr->{last_node_id}, "\n"; $t = \%{$t->{$item}}; } } print "\n", Dumper(\%tree), "\n"; print "\nThe Complete Tree:\n"; print $tree->create_report(); __DATA__ foo/bar bar/foo foo/bar/foo foo/bar/foo/bar/bar/foo foo/bar/bar/bar
if the table categories is not created from scratch this will not work. So I have to find also answer to this question, anyone can help me :)

In reply to Re: duplicates in DB tree by 2ge
in thread duplicates in DB tree by 2ge

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.