rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
before i went any further i just wanted to see if anyone could suggest a better way of dealing with it?#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $term = "( foo ) AND ( bar OR boo ) NOT ( far )"; # This regex isn't right my (@matches) = ( $term =~ /( )?(AND|OR|NOT)?( )?(\((.*)\))?/g ); # Testing print $_,"\n" foreach (@matches); # My plan was pull out all the parens and their contents # + the preceeding condition # then modify those result to put into a hash in the same # structure as below. # This is what the results should come out as my %tests = (); $tests{1} = { condition => "", terms => [ "foo" ] }; $tests{2} = { condition => "AND", terms => [ "bar", "OR foo" ] }; $tests{3} = { condition => "NOT", terms => [ "far" ] }; print Dumper(\%tests); exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Logical expressions
by Zaxo (Archbishop) on Jun 05, 2007 at 03:59 UTC | |
by rsiedl (Friar) on Jun 06, 2007 at 02:17 UTC | |
|
Re: Logical expressions
by GrandFather (Saint) on Jun 05, 2007 at 04:10 UTC | |
|
Re: Logical expressions
by jZed (Prior) on Jun 05, 2007 at 05:01 UTC | |
|
Re: Logical expressions
by ysth (Canon) on Jun 05, 2007 at 08:14 UTC | |
by ikegami (Patriarch) on Jun 05, 2007 at 15:07 UTC | |
by rsiedl (Friar) on Jun 06, 2007 at 02:21 UTC | |
|
Re: Logical expressions
by ikegami (Patriarch) on Jun 05, 2007 at 14:58 UTC | |
|
Re: Logical expressions
by jbert (Priest) on Jun 05, 2007 at 09:51 UTC | |
by raptur (Acolyte) on Jun 06, 2007 at 02:27 UTC | |
by rsiedl (Friar) on Jun 06, 2007 at 02:27 UTC | |
by jbert (Priest) on Jun 06, 2007 at 06:33 UTC |