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

Re: A Switch Case for multi-state returns.

Thread Previous | Thread Next
From:
drieux
Date:
March 31, 2002 10:31
Subject:
Re: A Switch Case for multi-state returns.
Message ID:
765D6B14-44D5-11D6-AE45-0030654D3CAE@wetware.com
>> ??-
>> @state="MA CI DE IN OH";

let me try that another way - without the bugs:

vladimir: 81:] perl Switch.pl MA CI bob OH
Process Says: MA_response
Process Says: CI_response
we do not know about state bob
Mr Wizard the stateField OH unguarded at Switch.pl line 41.
vladimir: 82:]  sed 's/^/### /' Switch.pl
### #!/usr/bin/perl
###
### use strict;
###
### my %data;
###
### #fill in 11 other states
### my @state = qw(MA CI DE IN OH);
###
### #Make each element of @state a key of hash %data
### #@data{@state } = (1) x @state;
### %data = map { $_ => 1 } @state;
###
### my $response='';
###
### foreach my $statefield (@ARGV) {
###
###     # read in the args as states
###
###     if ($data{$statefield} ) {
###         #
###         # Use a switch through
###         #
###         $_ = $statefield;
###         SWITCH: {
###
###             /MA/ && do {
###                 #do MA specific stuff
###                 $response='MA_response';
###                 last SWITCH;
###                 }; # end do MA stuff
###
###             /CI/ && do {
###                 #do CI specific stuff
###                 $response='CI_response';
###                 last SWITCH;
###             }; # end do MA stuff
###
###
###             die "Mr Wizard the stateField $statefield unguarded";
###
###         } # end of switch
###
###         print "Process Says: $response\n";
###     } else {
###         print "we do not know about state $statefield \n";
###     } # end if statefield
###
### }# end foreach
###
### exit(0);
vladimir: 84:]


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