Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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;


Comment on Re: Need a start point for resolving {[()]}
Download Code
Replies are listed 'Best First'.
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 romping around the Monastery: (8)
As of 2015-07-29 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls