Re: parsing a tree like structure
- From: yitzle@xxxxxxxxxxxxxxxxxxxxx (Yitzle)
- Date: Thu, 26 Jun 2008 13:06:15 -0400
This code is a start. It needs some playing with, still.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
open my $FH, "< t" or die;
my %root = ();
my $depth = 0;
my $curNode = \%root;
while ( my $line = <$FH> )
{
chomp $line;
$line =~ /^(\s*)/;
my $leadingSpace = length $1;
if ( $line =~ /^\s+\\==\+(.*) :$/ ) {
my $nodeName = $1;
$curNode->{ $nodeName }{ '__PARENT__' } = $curNode;
$curNode = $curNode->{ $nodeName };
} elsif ( $line =~ /^\s+\|----([^.]+)\.+([^.]+)$/ ) {
$curNode->{ $1 } = $2;
}
}
print Dumper ( \%root );
.
- References:
- parsing a tree like structure
- From: Pat Rice
- parsing a tree like structure
- Prev by Date: Re: parsing a tree like structure
- Next by Date: Re: parsing a tree like structure
- Previous by thread: Re: parsing a tree like structure
- Next by thread: Re: parsing a tree like structure
- Index(es):
Relevant Pages
|