in reply to build mysql data structure from text file
This code seems to print out the data that you want. It's simple enough to change the code to insert the data into a database instead of printing it out.
--#!/usr/local/bin/perl use strict; use warnings; my @parents = (0); my $prev_tabs = 0; while (<DATA>) { chomp; my $tabs = tr/\t//d; if ($tabs > $prev_tabs) { push @parents, $. - 1; } elsif ($tabs < $prev_tabs) { $#parents = $tabs; } print "$. : $_ : $parents[-1]\n"; $prev_tabs = $tabs; } __END__ cat1 cat1,sub1 cat1,sub1,sub-sub1 cat1,sub2 cat2 cat3 cat3,sub1
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: build mysql data structure from text file
by fireartist (Chaplain) on May 13, 2003 at 12:13 UTC | |
by davorg (Chancellor) on May 13, 2003 at 12:16 UTC | |
by fireartist (Chaplain) on May 13, 2003 at 12:29 UTC |