On Tue, 12 Apr 2005, David Gilden wrote:

> I am trying to create case statement, and I am not sure I am on the right 
> track,
> any comments?

Would something like this get the same result?

    my %form_action = (
        000 => sub {}, # silently ignore this one
        123 => handle_form(123);
        456 => handle_form(456);
        789 => sub { croak "Can't handle form 789: ", @_; },
    );

    my $form_handler = $form_action{$whichForm};

    sub handle_form {
        my $form      = shift;
        my $subject   = "$form Form";
        my $recipient = "[EMAIL PROTECTED]";
        my $cc        = "[EMAIL PROTECTED]";
        return ($form, $subject, $recipient, $cc);
    }

Etc. Where the cases are similar, pass them off to a common subroutine. 
If you need something unique (and short), an inline subroutine will 
work. Then your following code just does a lookup into the hash.

Also, as a side note, if $whichForm is numeric, you should just use the 
nueric comparisons rather than the string ones:

    if $whichForm eq "123"   # bad!
    if $whichForm = 123      # good!




-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to