I discussed with the teammates and convinced them to go for 'dispatch table'. Just want to know will the 'dispatch table' allow regex? As you can see we're using regex in if-else part. I guess I'll have to use Tie::RegexHash.
Regarding the Perl version: I don't know when are they (my company) gonna update it. I heard that we'll use 5.12 in the next update of our product though. On Thu, Nov 22, 2012 at 3:32 PM, Paul Johnson <p...@pjcj.net> wrote: > On Thu, Nov 22, 2012 at 11:37:15AM +0530, Chankey Pathak wrote: > > In our company we were using this code (given at the end) for about 10 > > years and it worked fine. > > > > Some days ago we faced some issues and we had to re-code the complete > > package, we decided to replace this code with Switch module by Damian (in > > order to improve the readability of code). > > > > Everything is working fine for us. > > > > Later I found on Perlmonks <http://www.perlmonks.org/?node_id=486756> > that > > Damian had put this module under > > > > Damian modules you shouldn't use in production because their purpose is > to > > explore and prototype future core language features. > > > > But it is working fine for us because we are not hitting the limitations > of > > this module (I guess). > > > > Now I ask you guys to please have a look at the both implementations > > (nested if else vs switch) and let me know whether using Switch in the > > newer implementation is fine or are we creating some future problems for > > us? Is using Switch in the code given below fine or are there any hidden > > bugs/problems? > > > > I've already read the bugs and reviews of this module on CPAN and > Perlmonks > > and I guess our code is far away from hitting those bugs (I think so). > > > > We are using Perl 5.8.5. > > > > *PS:* I know the alternatives of Switch, we have given/when in Perl 5.10, > > we can use dispatch table and other solutions which are specified > > here< > http://stackoverflow.com/questions/844616/obtain-a-switch-case-behaviour-in-perl-5 > >, > > but right now we just want to compare the new implementation which uses > > Switch. > > > > > > Code: > > > > *Using nested if else: http://paste.debian.net/211434/* > > > > *Using Switch: http://paste.debian.net/211435/* > > Hmmm. Is it safe? I suppose that depends on what you mean by that. If > it works in the conditions you care about I suppose you could say it is > safe. > > > or are we creating some future problems > > That's very possible. Or perhaps it will run for ten years before > someone else does a rewrite. > > I'm not sure why, knowing what you obviously do, you are wedded to using > Switch. I would be trying to use a dispatch table, if the case > insensitivity of $command would allow it. Failing that, I see nothing > particularly unreadable about the if/elsif/else chain. Especially if > you make the bodies into sepatate subs so you only have one sub call per > condition. Then you could line everything up vertically to make it very > readable. > > Even if you update your perl version I would stay away from given/when > for now. > > And you should update your perl version. It's unsuported, buggy and I'm > sure it has security problems which have been fixed in the last eight > years. (That's always a good case to make to management folk.) > > -- > Paul Johnson - p...@pjcj.net > http://www.pjcj.net > -- Regards, Chankey Pathak <http://www.linuxstall.com>