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
    Dave, Thanks for the tip. I am looking into the hash table method. I just wanted to pass along that perldoc is STILL down.

      perldoc.com gets a little flakey from time to time, for various reasons. Fortunately, if you have Perl, you have perldoc right on your own computer too. Try typing "perldoc perlintro", just for example. Also, with ActiveState Perl you have both the command line utility "perldoc", as well as an HTML version of the POD that is browsable with your favorite web browser.


      Dave

        Yes, I'm aware of the local copy within ActivePERL. I have used it on occassion. I just wanted to bring your attention to the dead link. I think I'm going to put my initial code up on my site shortly, then put the more optimized code with hash tables up later. My biggest concern at this point is that I have almost no clue about software version control. I guess my first copy will be v 0.01 :)