Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl Code Changes Behavior if Two Subroutine definitions are swapped

by haukex (Archbishop)
on Jul 27, 2016 at 14:20 UTC ( [id://1168643]=note: print w/replies, xml ) Need Help??


in reply to Perl Code Changes Behavior if Two Subroutine definitions are swapped

Hi Abhishek,

Please use <code> tags to format your code and example input. See also How do I post a question effectively?

A first quick analysis is that your problem seems to stem from the use of the Switch module - its use is discouraged, please see the section "Limitations" in its documentation. If I replace the switch statement with next if /^[*\/]|simulator\s+lang|^include/i;, your code appears to run the same no matter the order of the subroutines.

There may be other possible places for improvement, I haven't read the code in detail yet, but that seems to be the main problem.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Perl Code Changes Behavior if Two Subroutine definitions are swapped
by rkabhi (Acolyte) on Jul 27, 2016 at 14:44 UTC
    Hi Hauke,
    Thanks a lot for quick response !!
    Your response really helped.

    I am actually writing few perl codes for the first time for a project and want to be cautious with use of such modules. Is there any way I can get to know those basic modules whose use is not suggested?

    Thanks once again for your help!!

    --
    Abhishek

      Hi Abhishek,

      Modules whose use is discouraged is often noted in the module's documentation itself (for example, the top of the Switch page says "do not use if you can use given/when"). Otherwise, by looking at a distribution's CPAN page (this is the one for Switch), there are other clues as to when a module might not be good to use: if it has bad reviews, if it only had one release and/or hasn't had releases for many years, if its test statistics show a lot of failures, and/or if it has a lot of unresolved bugs. None of these things by themselves make a module bad, they are only clues, but if a module has a lot of these issues then you may want to stay away from it. The same clues can of course be used to tell if a module is "good": good reviews, several releases over several years, a low bug count, and good test results are all signs of a module being "good quality".

      Off the top of my head, some modules that are often used even though their use is nowadays discouraged: XML::Simple (is only useful for a very narrow range of tasks, there are better modules like XML::Twig, XML::Rules, or XML::LibXML), Switch (a few alternatives), and CGI (there are more modern web frameworks, such as Catalyst, Dancer/Dancer2, and Mojolicious). <update> File::Slurp has a lot of issues, better to slurp manually or use one of the other modules. </update>

      On the other hand, you can get a lot of good module suggestions from this site itself by reading threads with questions that relate to your tasks, or there is also Task::Kensho, a list of recommended modules for various tasks.

      Hope this helps,
      -- Hauke D

        Hi Hauke,

        I am out of words to thank you for your thorough explanation. Though for now I got the problem resolved by avoiding switch module. I will be referring to your response time and again before using any new module.

        Thanks a lot !!

        Best Regards,
        Abhishek

        Thank you, haukex, for this enlightening post.

        I doubt that I am alone in wondering why CPAN does not have a better method of finding and marking modules that may be, for lack of a better word, obsolete.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found