Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

using switch

by sicone (Initiate)
on Sep 29, 2005 at 12:56 UTC ( #496084=perlquestion: print w/replies, xml ) Need Help??

sicone has asked for the wisdom of the Perl Monks concerning the following question:

I think I understand the switch statement, but I would like to see some examples of it in use. I want to use it with the <STDIN> function, unless there is a better way.

Replies are listed 'Best First'.
Re: using switch
by castaway (Parson) on Sep 29, 2005 at 13:04 UTC
Re: using switch
by Corion (Pope) on Sep 29, 2005 at 13:05 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: using switch
by Roy Johnson (Monsignor) on Sep 29, 2005 at 13:55 UTC
    There are a couple of alternatives to the Switch module, which don't share its weakness of being source-filtered. See Switch::Perlish and (my own) Case.

    Caution: Contents may have been coded under pressure.
Re: using switch
by thundergnat (Deacon) on Sep 29, 2005 at 13:29 UTC

    Your best bet is to avoid using Switch at all, especially in production code. It is very easy to introduce very hard to trace bugs and is just too fragile.

    If you have a large number of possible branches use a dispatch table, otherwise, if-then-else (or ? : ).

Re: using switch
by Limbic~Region (Chancellor) on Sep 29, 2005 at 13:38 UTC
    sicone,
    As has been pointed out, using Switch in production code is discouraged. This will be mostly remedied in Perl6. Dispatch Tables don't offer the same degree of flexibility, but for specific problems are a great solution.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2020-06-04 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (32 votes). Check out past polls.

    Notices?