Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Use an array slices

by blakem (Monsignor)
on Feb 28, 2003 at 09:31 UTC ( #239379=note: print w/ replies, xml ) Need Help??


in reply to Use an array slices

Have you thought about what happens when you add the tenth (i.e. '10') branch?

-Blake


Comment on Re: Use an array slices
Re: Re: Use an array slices
by nite_man (Deacon) on Feb 28, 2003 at 14:38 UTC
    This decision doesn't have pretensions on absolutly universality. I have just had a case with fixed choises. If I will add the tenth branch, I will add a choice for it.
    #!/usr/bin/perl -w use strict;
      I assume that case would look something like this:
      #!/usr/bin/perl -wT use strict; my $value = 10; SWITCH: for ($value) { /0/ && do {print "ZERO\n"; last; }; /1/ && do {print "ONE\n"; last; }; /10/ && do {print "TEN\n"; last; }; print "NONE OF THE ABOVE\n"; }
      Can you guess what the output is? Run it and find out.

      -Blake

        It produces the ZERO message :) Matching the whole string produces better results:

        #!/usr/local/bin/perl use strict; use warnings; my $value = 10; SWITCH: for ($value) { /^0\z/ && do {print "ZERO\n"; last; }; /^1\z/ && do {print "ONE\n"; last; }; /^10\z/ && do {print "TEN\n"; last; }; print "NONE OF THE ABOVE\n"; }
        Well, "ZERO". But that's easily solvable (although it looks less pretty):

        #!/usr/bin/perl -wT use strict; my $value = 10; SWITCH: for ($value) { /^0$/ && do {print "ZERO\n"; last; }; /^1$/ && do {print "ONE\n"; last; }; /^10$/ && do {print "TEN\n"; last; }; print "NONE OF THE ABOVE\n"; }

        Leonid Mamtchenkov

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://239379]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2015-07-03 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls