Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Need a start point for resolving {[()]}

by hdb (Prior)
on Jun 13, 2013 at 07:21 UTC ( #1038695=note: print w/replies, xml ) Need Help??

in reply to Need a start point for resolving {[()]}

This piece of code could be a starting point. Also look at Re: Convert Tcl Keyed List to Perl where I use the same technique in a different context.

# node 1030367 use strict; use warnings; my $expr = '(A&(B&C)|((C&D)|\((A EQ 1)))'; 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 $expr =~ /./g;

Replies are listed 'Best First'.
Re^2: Need a start point for resolving {[()]}
by exilepanda (Pilgrim) on Jun 13, 2013 at 11:39 UTC
    Wow! This inspires a lot, by level shifting and tabbing! A very nice start point! Looks much more neat and firm. Thanks for the lead!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038695]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2016-10-27 15:44 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (366 votes). Check out past polls.