|Problems? Is your data what you think it is?|
Re: Switch/case as a dispatch table with C-style fall-throughby Animator (Hermit)
|on May 13, 2005 at 10:00 UTC||Need Help??|
Here are some others thoughts:
In your current implementation you define the break function in the caller's package, but what if there is already a break function in it?
Wouldn't it be better to allow a user-defined name, and/or return a blessed version of the coderef and make it possible to call the break method on it? (in order to this to work properly you will need to pass the object itself to the code-ref of the eval)
And shouldn't the break function stop the execution of the code? (although this might be rather complicated..., as in adding 'last' to the break sub won't work if the code has it's loop, using die/eval might work but that would be slower...)
And what about implementing next, redo and last?
Where next could mean, jump to the next case statement (that is the fallthru one, possibile with or without ignoring the fallthru variable (if break doesn't return immediatly))
Redo could mean redo the case-coderef. (Updated (old text:
And last could be an alias to break...
By creating your own loop you can figure out which one was called... Some code to demonstrate: