Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re3: Use an array slices

by blakem (Monsignor)
on Mar 01, 2003 at 00:37 UTC ( #239603=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Use an array slices
in thread Use an array slices

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


Comment on Re3: Use an array slices
Download Code
Replies are listed 'Best First'.
Re: Re3: Use an array slices
by hypochrismutreefuzz (Scribe) on Mar 17, 2003 at 15:04 UTC

    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"; }
Re: Re3: Use an array slices
by TVSET (Chaplain) on Apr 28, 2003 at 07:14 UTC
    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://239603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-30 05:48 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 (270 votes), past polls