in reply to Non deliminatd Nested text
Greetings Dr.Altaica,
You have an interesting situation. I'm sure there must be a module out there that does nearly exactly what you want, but since you specifically asked for something that will work "only in the standared distubution of Perl," here's my code:
#!/usr/bin/perl -w use strict; my $input = '[S [NP This NP] [VP is [NP [NP the turning point NP] ' . '[PP to [NP the left NP] PP] NP] VP] . S]'; $input =~ s/^\[S\s*(.*?)\s*S\]$/$1/; my $bracket_count = 0; my @output; my $build_var; foreach (split(//, $input)) { $build_var .= $_; if (/\[/) { $bracket_count++; } elsif (/\]/) { $bracket_count--; } if ($bracket_count == 0) { push @output, $build_var if ($build_var ne ' '); $build_var = ''; } } foreach (@output) { print '"', $_, '"', "\n"; }
It's not fancy or nice, and probably will need to be patched a bit for situations that fall outside of your given example. However, it does seem to return the results that you want.
-gryphon
code('Perl') || die;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Non deliminatd Nested text
by tommyw (Hermit) on Oct 26, 2001 at 05:56 UTC | |
|
Re: Re: Non deliminatd Nested text
by Dr.Altaica (Scribe) on Dec 10, 2001 at 16:07 UTC |