Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl/Unix case

by gothic_mallard (Pilgrim)
on Oct 22, 2004 at 15:41 UTC ( [id://401532]=note: print w/replies, xml ) Need Help??


in reply to Perl/Unix case

Perl unfortuantly doesn't have a case statement but, as with most things, TMTOW to roll your own.

The simplest, obviously, is with a set of if...elsif...else statements which does essentially the same thing if looking a little less elegant.

The hash is another possibility and maybe faster than the if... route (but don't quote me on that), although unless you have lots of options then the difference is probably going to be negligable.

--- Jay

All code is untested unless otherwise stated.

Replies are listed 'Best First'.
Re^2: Perl/Unix case
by thor (Priest) on Oct 23, 2004 at 04:29 UTC
    a set of if...elsif...else statements which does essentially the same thing
    It's almost the same. From what I recall of C programming, that language implements switches with jump i.e. it knows where in memory to find the code it needs to execute. This is akin to the hash solution that you mention. I've seen perl core dump on a program with too large a block of if..elsif..elsif... . That was a couple of years ago, but either way, I think that the dispatch table is the better solution for more reasons than just that.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

Log In?
Username:
Password:

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

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

    No recent polls found