in reply to splitting data

This is a classical CS problem of infix parsing. See

There are many other resources on this as well.

This type of a problem is often presented as parsing infix notation for a 4 function calculator with parenthesis. That might give you a starting point.

--MidLifeXis

Replies are listed 'Best First'.
Re^2: splitting data
by hdb (Monsignor) on Apr 24, 2013 at 11:42 UTC

    I took this problem as inspiration to write a little script to visualize matching parantheses. I probably got carried away and it is not helping on the original problem.

    use strict; use warnings; my $tlp_p2 = "(((((((NOT(tlp_p0(0) XOR tlp_add_p0(0)) AND NOT(tlp_p0(1 +) XOR tlp_add_p0(1))) AND NOT(tlp_p0(2) XOR tlp_add_p0(2)))"; my $level = 0; my $tab = "| "; my %action = ( '(' => sub { print "\n", $tab x ++$level, shift }, ')' => sub { print "\n", $tab x $level--, shift }, 'default' => sub { print shift }, ); ( $action{$_} // $action{'default'} )->($_) for $tlp_p2 =~ /./g;

    The last line reads each character of the string $tlp_p2 individually and calls the corresponding sub from hash %action.