[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] case and elsif



At 21:49 -0400 1999.08.26, Emmanuel. M. Decarie wrote:
>I feel ashamed, but I didn't find yet a good way to do a case
>structure in Perl instead of this horrible kludge with elsif. But for
>this script to work it really have to check every condition in this
>order. Anyone want to enlighten my stupidity? Its a multiparts form.

It isn't a kludge.  It's really the way to do it.

>I had a look at the Camel book (p. 104), but really, I feel lost to
>adapt the SWITCH statement to what I want to do here. And there is an
>example in the Ram book (p. 697), but maybe I'm too tired, but I
>don't see how I can put this in a hash. Maybe there a FAQ somewhere
>that I didn't look.

The problem is that this is not a switch / case statement, really.  What
those kind of statements do is test a single parameter for multiple
possible values.  You have multiple parameters to test for multiple
possible values.  You could clean it up with the ?: operator:

  param() == 0                    ? pageMotDePasse()      :
  param('ok') eq $motDePasse      ? pageDirection()       :
  param('decide') eq '1'          ? pageChoix()           :
  param('decide') eq '0'          ? pageLettre()          :

But that does not work well with anything more than a single statement
between the ? and : (and some people don't like it for flow control at all).

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org