Moe has asked for the wisdom of the Perl Monks concerning the following question:
The code as shown above will end with 1|| 0), instead of just 1. However, if I change the | to & in the test string? It works fine. Which puzzles me to no end. So Great Monks, whose wisdom far outstrips mine own...how do I make this work more consistently? ~Moe~#! /usr/bin/perl #sample string. $string = "((2 > 1) | ('word' eq 'toy'))"; #next line converts user-specified operators into Perl #logical operators. $string =~ s/([&|]{1})/$1$1/g; print "Initial parsed string = $string\n"; #Look ahead assertion. while ($string =~ /\(((?:[^()])*?)\)/) { my $val = (eval $1) ? 1 : 0; print "Case to be evaluated = $1\n"; print "Evaluated value = $val\n"; $string =~ s/\($1\)/$val/; print "Parsed string = $string\n"; } print "Result: $string\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing parenthetical arguments recursively
by Moe (Novice) on Aug 15, 2003 at 18:07 UTC | |
by Anonymous Monk on Aug 15, 2003 at 19:38 UTC | |
by waswas-fng (Curate) on Aug 15, 2003 at 22:29 UTC | |
by Moe (Novice) on Aug 16, 2003 at 16:19 UTC | |
|
Re: Parsing parenthetical arguments recursively
by dragonchild (Archbishop) on Aug 15, 2003 at 17:53 UTC | |
by Moe (Novice) on Aug 15, 2003 at 17:59 UTC |