develooper Front page | perl.beginners | Postings from March 2002

A Switch Case for multi-state returns.

Thread Previous | Thread Next
From:
drieux
Date:
March 31, 2002 09:56
Subject:
A Switch Case for multi-state returns.
Message ID:
999B7BD4-44D0-11D6-B64F-0030654D3CAE@wetware.com

On Sunday, March 31, 2002, at 08:25 , Zeus Odin wrote:
> #!D:\perl\bin\perl -w
> use strict;
> my %data;
>
> # fill in 11 other states
> my @state = qw(MA CI DE IN OH);
> @data{ @state } = (1) x @state;
[..]

>    If ( $data{$statefield} ) {
>    # OR If ( $data{uc($rs->Fields('state')->value)} ) {
>       # Process data
>    }

way cool trick, but doesn't this still need to
have a 'Swithch like break out:

if ($data{$statefield} ) {
    #
    # Use a switch through
    #
    $_ = $statefield
    SWITCH: {

         /MA/ && do {
			#do MA specific stuff
			.....
			last SWITCH;
         } # end do MA stuff

         /CI/ && do {
			#do MA specific stuff
			......
			last SWITCH;
         } # end do MA stuff

		.....

         die "Mr Wizard the stateField $statefield unguarded";

    } # end of switch

} else {
         # not in our state List
}

> ??-
> @state="MA CI DE IN OH";


this way as the @state list grows or shrinks the one simply
adds in one more switch statement....

it's the 'last SWITCH' part that breaks it out.

The die is there fore the absurd case that while the
@state list was updated - someone forgot to specify
what to DO with that statement.... which of course
would not happen.... we all know.

ciao
drieux

---


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About