Do you really need to store your conditions in a string? If the context permits it, you may as well store it in a code reference, as shown in the following session under the debugger:
DB<1> @field = qw/0 0 0 0 0 0 PM 0 CAVENDI/; DB<2> $code_ref = sub {$field[shift] eq 'PM' && $field[shift] eq ' +CAVENDI'}; DB<3> $ignore_flag = $code_ref->(6, 8) DB<4> p $ignore_flag 1 DB<5> $ignore_flag = $code_ref->(3, 8) DB<6> p $ignore_flag DB<7> print "true" if $code_ref->(6, 8) true DB<8> print "true" if $code_ref->(3, 8) DB<9>
Here, I have added a feature (dynamic passing of the array subscripts as parameters to the coderef), but the subscripts might as well be hard coded as in your original example.
In reply to Re: testing an if statement in a string
by Laurent_R
in thread testing an if statement in a string
by brcjacks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |