[mplspm]: Howto do switch with fall-through

Dan Oelke Dan at oelke.com
Thu Aug 29 17:20:33 CDT 2002


Hmmmmm - I was hoping for a cleaner solution, but adding the $doAnyway 
thing would get me exactly the behavior I wanted.  Now why didn't I think 
of that type of solution.....

I did look at Switch.pm (before I wrote my first message even) - and it 
does have "fall-through" behavior, but the way it works I would have to do 
a $doAnyway type of pattern to the code.

Thanks a million!
Dan

PS - I haven't been able to make any of the gatherings for quite a while 
now, so maybe this has been discussed already - but has anyone else here 
seen Ken William's boxers video?  This is the same Ken Williams - correct???

At 03:26 PM 8/29/02 -0500, Jay Jacobs wrote:
>I'm not sure where you get your switch info from, but I don't understand
>how in the world you'd ever get
> > I see only "Baseline" instead of "Baseline Rebase Build"
>from the code your suppyling.
>
>anyway, perldoc is your friend, take a look at the perldoc info on "last",
>in your situation you'd have to specify the LABEL that you want to "last"
>from, but it still wouldn't produce your desired result.
>
>last SWITCH if ($onlyFlag);
>
>
>my $onlyFlag = 1;
>my $doAnyway = 0;
>SWITCH: {
>   if (/ONE/) {
>     print "ONE\n";
>     if ($onlyFlag) {
>       last SWITCH:
>     } else {
>       $doAnyway = 1;
>     }
>   }
>   if ($doAnyway || /TWO/) {
>     print "Two\n";
>     if ($onlyFlag) {
>       last SWITCH:
>     } else {
>       $doAnyway = 1;
>     }
>   }
>   if ($doAnyway || /THREE/) {
>   .... etc
>}
>
>This is written in this email and untested, but the theory is there
>
>
>
>
>On Thu, 29 Aug 2002, Dan Oelke wrote:
>
> > I have a perl programming question for you....
> >
> > I want to create a switch type statement with fall-through like C provides.
> >
> > I have a script where it does a number of things in different "phases" for
> > lack of a better phrase.  What I figured I could do was to pass in the
> > phase I wanted to start in, and the script would pick up at that phase and
> > and proceed through the rest.  Add an extra flag and I could have it do
> > only that phase.
> >
> > Here is a code snippet illustrating what I want.
> > #-----------------------------------------------
> > use strict;
> >
> > my $onlyFlag = 1;
> > $_ = $ARGV[0];
> >
> > SWITCH: {
> >    if (/Deliver/) {
> >      print "Deliver\n";
> >      if($onlyFlag) {last;}
> >    }
> >    if (/Baseline/) {
> >      print "Baseline\n";
> >      if ($onlyFlag) {last;}
> >    }
> >    if (/Rebase/) {
> >      print "Rebase\n";
> >      if ($onlyFlag) {last;}
> >    }
> >    if (/Build/) {
> >      print "Build\n";
> >      if ($onlyFlag) {last;}
> >    }
> > }
> > #-----------------------------------------------
> >
> > Except that when I execute
> >        perl test.pl Baseline
> > I see only "Baseline" instead of "Baseline Rebase Build"
> >
> > Any ideas on how I can structure a switch type statement to get what I
> > want, OR maybe just another cool way to restructure this code to get the
> > same effect?
> >
> > Thanks,
> > Dan
> >
> >
> >
> > --------------------------------------------------
> > Minneapolis Perl Mongers mailing list
> >
> > To unsubscribe, send mail to majordomo at pm.org
> > with "unsubscribe mpls" in the body of the message.
> >
>
>
>
>
>
>--------------------------------------------------
>Minneapolis Perl Mongers mailing list
>
>To unsubscribe, send mail to majordomo at pm.org
>with "unsubscribe mpls" in the body of the message.



--------------------------------------------------
Minneapolis Perl Mongers mailing list

To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.



More information about the Mpls-pm mailing list