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

Falling through Perl 5.10 switch statement

by Thilosophy (Curate)
on Apr 07, 2007 at 02:01 UTC ( [id://608788]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    given($data) {
        when (1) { say 'one' ; };   ## no "break" needed
        when (2) { say 'two' ; };
        default  { say 'something else';  };
    }
    
  2. or download this
    # this code does not work !
    # it will say "something else"
    ...
        when (2) { say 'one or two' ; };
        default  { say 'something else';  };
    }
    
  3. or download this
    # this works, is shorter and easier to read
    given($data) {
        when ([ 1, 2]) { say 'one or two' ;  };
        default  { say 'something else';  };
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://608788]
Approved by Joost
Front-paged by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found