Re: how to remove blocks between nested brackets



_
Si (silicium_at_h@xxxxxxxxxxxxxx) wrote on VCCLXVI September MCMXCIII in
<URL:news:47a1c3a1$0$902$ba4acef3@xxxxxxxxxxxxxx>:
:) Beeing new to perl and not wanting to learn using it like assembler, I
:) need to delete parts of a single line (possibly long) that are enclosed
:) between nested brackets:
:)
:) abcd efgh [ij: 123-[456]-klm; nop-789]; qrst; uvw [xyz: 98-76-[ef]; gh;
:) ijkl] (mnop)
:)
:) The comments between [] must be discarded to split with ';' delimiter.
:) The expected result is:
:) array[0] == "abcd efgh"
:) array[1] == "qrst"
:) array[2] == "uvw (mnop)"
:)
:) Thanks for a magic formula.

The magic formula is: \s*(\[[^][]*+(?:(?1)[^][]*+)*\])


my $_ = "abcd efgh [ij: 123-[456]-klm; nop-789]; qrst; uvw " .
"[xyz: 98-76-[ef]; gh;ijkl] (mnop)";

s {\s*(\[[^][]*+(?:(?1)[^][]*+)*\])} {}g;

my @array = split /;\s*/;

say qq {array[$_] == "}, $array [$_], qq {"} for 0 .. $#array;

__END__
array[0] == "abcd efgh"
array[1] == "qrst"
array[2] == "uvw (mnop)"



Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
.



Relevant Pages

  • how to remove blocks between nested brackets
    ... Beeing new to perl and not wanting to learn using it like assembler, I need to delete parts of a single line that are enclosed between nested brackets: ...
    (comp.lang.perl.misc)
  • Re: Crenshaws Compiler Tutorial: 68k Asm to X86 Vs Interpreting, Newbie Qs on Parsing and Pascal
    ... I chose Perl because it is more high-level and it is a little ... language not supporting eval, such as Java. ... The assembler version uses labels which are supported by the Assembler ... So in stead I'd like to interpret and run the code while it is encountered ...
    (comp.compilers)
  • Re: Assembler vs. Perl
    ... Bei Perl ist irgendwo bei 65 Tausend Schluss. ... Assembler kannst du im grunde den ganzen CPU-Cache ausfüllen. ... einer Zahl auf den Monitor muss man richtig Ahnung von Assembler ...
    (de.comp.os.unix.linux.misc)
  • Re: Assembler vs. Perl
    ... eine FOR-Schleife mit print ... Assembler hingegen war komplizierter, ich hab die Ausgabe ... "time perl beispiel.pl" ... Perl Programm. ...
    (de.comp.os.unix.linux.misc)
  • Re: need help with hash - been too long working in Perl
    ... You are trying to open "msj_sare.lst" but your error message says you ... I am wanting to print out the data in the following format: ... It *looks* like you might want the second column in sorted order but the ... use Perl; ...
    (comp.lang.perl.misc)