Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: How to use select

by ZlR (Chaplain)
on Mar 05, 2005 at 10:21 UTC ( #436877=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to use select
in thread How to use select

Ah, then what you want is a switch like statement .
There's a module : switch .

Or you can do it in a great number of various ways, the most common one is using a named block with last:

SWITCH: { if (expression) { statement(s); last SWITCH; } if (expression) { statement(s); last SWITCH; } default statement(s); }
update : don't try to be funky by using that switch module :) just use the if / last style ! See the answers by corion , holli and virtualsue !!


Comment on Re^3: How to use select
Download Code
Re^4: How to use select (Switch.pm considered harmfull)
by Corion (Pope) on Mar 05, 2005 at 13:12 UTC

    I cannot recommend the use of Switch.pm to anybody. It is a fragile, unmaintained source filter that introduces bugs into your code that are hard to track down unless you already know what to look for. Hand-coding the switch-statement is the only choice that is hassle-free and doesn't introduce bugs in unrelated pieces of code.

Re^4: How to use select
by holli (Monsignor) on Mar 05, 2005 at 13:21 UTC
    Note that Switch.pm is a source filter an as such notorious unreliable. I remember a discussion in the CB a while ago where quantum had some code on his scratchpad that had a mysterios error. The script included a subroutine, that wasn't called. The strange thing: When you commented it out the error went away.

    Three or four monks (including me) who worked on the code could only scratch their heads. Then virtualsue pointed out the script used Switch.pm. Removing the use Switch; statement fixed the problem.

    From the docs of Switch:
    There are undoubtedly serious bugs lurking somewhere in code this funky :-)


    Update: Corion told me quantum's name. I had forgotten it.


    holli, /regexed monk/
Re^4: How to use select
by virtualsue (Vicar) on Mar 05, 2005 at 13:35 UTC
    Recently somebody was asking for help in the chatterbox, tearing his hair out over some strange bug. It turned out that the sole cause of the problem was the fact that he had a "use Switch;" statement in his code. He wasn't actually using anything from Switch, he had just neglected to remove the use statement after a failed attempt to get it to DWHW.

    I wholeheartedly second your other suggestion for implementing a C-style switch. :-)

    FWIW I don't understand why Switch.pm is included in core. It's such an attractive nuisance for those who come from a C/C++ background and miss having a switch construct. The little disclaimer in the "Bugs" section of Switch's pod isn't really enough of a warning.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-09-23 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls