Like LanX, I have some reservations about your basic approach, but that said, just using a split limit of 2 seems to do the trick here:
(Update: In the qq(failure_reason <> 'Response=X') example given, you only actually want to split once.)c:\@Work\Perl\monks>perl -wMstrict -e "my $clause = qq(failure_reason <> 'Response=X'); my @operators = qw ( <> != !< !> <= >= < > = ); my $opr_regex = '(\s*' . join('\s*|\s*', @operators) . '\s*)'; my ($fld,$opr,$val) = split /$opr_regex/, $clause, 2; print \"\n\$opr_regex = $opr_regex\n\n\"; print \"\$clause = $clause\n\n\"; print \"\$fld = ^|$fld^|\n\"; print \"\$opr = ^|$opr^|\n\"; print \"\$val = ^|$val^|\n\n\"; " $opr_regex = (\s*<>\s*|\s*!=\s*|\s*!<\s*|\s*!>\s*|\s*<=\s*|\s*>=\s*|\ +s*<\s*|\s*>\s*|\s*=\s*) $clause = failure_reason <> 'Response=X' $fld = |failure_reason| $opr = | <> | $val = |'Response=X'|
Give a man a fish: <%-{-{-{-<
In reply to Re: Skip quoted string in regex
by AnomalousMonk
in thread Skip quoted string in regex
by roho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |