Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: How to use select

by agynr (Acolyte)
on Mar 05, 2005 at 10:00 UTC ( [id://436875]=note: print w/replies, xml ) Need Help??


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

What I want is to use select statement as in other languages like C or C++ ..... I want to select from a no. of choices. Please let me know if it is possible or not . If it is possible then what is the ppd file to use.

Replies are listed 'Best First'.
Re^3: How to use select
by virtualsue (Vicar) on Mar 05, 2005 at 13:38 UTC
Re^3: How to use select
by ZlR (Chaplain) on Mar 05, 2005 at 10:21 UTC
    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 !!

      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.

      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/
      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://436875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found