in reply to PERL Conditionals
You have a few options, and which one you'll use depends on the nature of the conditional test, the actions you want to branch to, and the number of options, among other things. Here are a couple of examples:
First, a block method:
SWITCH: { $condition1 and do{ stuff(); last SWITCH; }; $condition2 and do{ other(); last SWITCH; ); default(); }
Second, a hash table method:
my %options = ( key1 => \&sub1, key2 => \&sub2, key3 => \&sub3 ); $options{$condition}->();
Those are two very common variants. But there are many others, due to Perl's flexibility. Check perlsyn for more info.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PERL Conditionals
by nashr (Novice) on Nov 10, 2004 at 15:18 UTC | |
by davido (Cardinal) on Nov 10, 2004 at 17:12 UTC | |
by nashr (Novice) on Nov 10, 2004 at 17:33 UTC |