Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Is this code which is using safe?

by Chankey Pathak (Novice)
on Nov 22, 2012 at 07:04 UTC ( #1005070=perlquestion: print w/replies, xml ) Need Help??
Chankey Pathak has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

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 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 here on 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, but right now we just want to compare the new implementation which uses Switch.


Using nested if else:

Using Switch:

  • Comment on Is this code which is using safe?

Replies are listed 'Best First'.
Re: Is this code which is using safe?
by GrandFather (Sage) on Nov 22, 2012 at 08:22 UTC

    Rather than provide links to pages that may cease to be, please provide small samples of your code inside <code> tags in your node.

    The Switch module is a source filter which is something to generally avoid for production code. If you can't use 5.10 or later and given/when then I'd strongly recommend one of the other alternatives to switch that you mention. Depending on what your code looks like, I'd tend toward a dispatch table.

    True laziness is hard work
      @<code>:Okay I'll take care of it from next time.

      @Switch: Okay, thanks.
Re: Is this code which is using safe?
by Anonymous Monk on Nov 22, 2012 at 08:13 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005070]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-22 00:14 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.