in reply to Text Conversion
Oringinal Reply: The way you store your data is really problematic. Use a flatened structure like _section1, _section2, _section12, _section13 etc is not a good idea at all.use strict; open(IN, "<", "data.txt"); my @in = <IN>; close(IN); open(OUT, ">", "out.txt"); my $out = ""; foreach my $in (@in) { chomp($in); if ($in =~ m/^(.*?)\\(.*?)\s*$/) { $out .= " $2"; } else { if ($out ne "") { print OUT "$out\n"; } $in =~ m/^(.*?)\s*$/; $out = $1; } } print OUT "$out\n"; close(OUT);
If your case is that you need to store some text for section1 itself, even though it is not a leaf, then store those things in:$source{_source}->[0]
If this section1 is not a leaf, itself would be another array-ref, and its first child would be$source{_source}->[0][0]#dedicate 0 to myself
This goes on and on.$source{_source}->[0][1]#my 1st child
use Data::Dumper; use strict; my %source; $source{_source} = []; $source{_source}->[0] = []; $source{_source}->[0][0] = "section1";#myself $source{_source}->[0][1] = "section11";#1st child $source{_source}->[0][1] = "section12";#2nd child print Dumper(\%source);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Text Conversion
by artist (Parson) on Dec 30, 2002 at 20:54 UTC | |
|
Re: Re: Text Conversion
by artist (Parson) on Dec 30, 2002 at 21:52 UTC |