in reply to Re^3: Using a stored condition
in thread Using a stored condition

Thanks... Its working now... I would like to go with the first method but could you show me how to execute multiple statements using it?

Replies are listed 'Best First'.
Re^5: Using a stored condition
by TGI (Parson) on Mar 03, 2008 at 00:43 UTC

    If you have a small number of different conditions, you may wish to use a dispatch table.

    use strict; use warnings; my %condition = ( '(A&B)|(C&D)' => sub { my ($aa, $bb, $cc, $dd) = @_; return ($aa && $bb ) || ($cc && $dd ); }, 'A|(B&C&D)' => sub { my ($aa, $bb, $cc, $dd) = @_; return $aa || ($bb && $cc && $dd ); } ); my @flags = qw( 0 1 1 1 ); my @conditions_to_check = ( 'A|(B&C&D)', 'FOO', '(A&B)|(C&D)' ); for my $cond_name ( @conditions_to_check ) { if( exists $condition{$cond_name} ) { if ( $condition{$cond_name} ->(@flags) ) { print "Condition '$cond_name' is true\n" } else { print "Condition '$cond_name' is false\n" } } else { print "Condition '$cond_name' is not defined\n"; } } __DATA__ Condition 'A|(B&C&D)' is true Condition 'FOO' is not defined Condition '(A&B)|(C&D)' is true


    TGI says moo

Re^5: Using a stored condition
by shmem (Chancellor) on Mar 02, 2008 at 23:50 UTC
    Stuff the expressions into an array and run a for() loop with that? But I'm beginning to suspect an XY problem here. What's X?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^5: Using a stored condition
by jettero (Monsignor) on Mar 02, 2008 at 23:45 UTC
    Maybe you could write them out to a file and run perl on it.

    -Paul