Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by hdb (Parson)
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;


Comment on Re: Need a start point for resolving {[()]}
Download Code
Re^2: Need a start point for resolving {[()]}
by exilepanda (Monk) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-09-03 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls