Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Switch.pm or possible alternatives

by broquaint (Abbot)
on May 21, 2005 at 14:28 UTC ( [id://459244]=note: print w/replies, xml ) Need Help??


in reply to Switch.pm or possible alternatives

What marvellous timing as I can point you to my new module, Switch::Perlish (which should be available on CPAN any moment now if it isn't already). So extrapolating from your node this code should do the job:
use Switch::Perlish; switch $your_var, sub { case 'this', \&this_function; case 'that', \&that_function; case 'the', \&the_function; case 'other', \&other_function; default sub { print "Nothing matched '$your_var'\n" }; };
HTH

_________
broquaint

Replies are listed 'Best First'.
Re^2: Switch.pm or possible alternatives
by BrowserUk (Patriarch) on May 21, 2005 at 15:39 UTC

    broquaint++. Very clever indeed.

    I wish I'd written that :). I have had half a dozen attempts at doing so and got near to something usable a few times, but always got hung up on weird syntax and error handling.

    You could remove the need for the 'sub' keyword on the 'default' with a prototype, but that would be inconsistant with 'case'. Now, if only prototypes allowed the use of & in the positions other than the first to accept a bare-block, this could be damn nearly perfect.

    Nice!


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re^2: Switch.pm or possible alternatives
by smack (Beadle) on May 25, 2005 at 11:18 UTC
    Thank you so much for your help. I will definitely be using this module!

    smack

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found