Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A couple of comments:

Those labels look like a good place to start. sub them out and pass the array.

Those large, gnarly if/elsif clauses would be my next step. Create a descriptively named sub like has_many_valid_lodgements, move the logic there and return true or false. This also has the advantage of self-documenting your code. No one will be able to quickly discern what

scalar(@all_lodgements) > 2 && ($total_all_lodged == $total_qcs_docs)
means.

Look for copy-and-paste code like the Date_Cmp's. Get rid of them. Make 1 sub and name it well.

Other Notes:

  • Think about writing tests, even with the code as it stands. The tests for this will have to be high level but you'll know if you break something (or even find a bug). As you refactor add smaller tests for the smaller components. It not only will keep you from breaking things, it helps you think about refactoring. Refactored code is generally easily tested.
  • Think about self documenting the code. You seem to use decent variable names continue that with the refactored subs. Think about leaving your code to someone else, and if they'll like you in the end :)
grep
One dead unjugged rabbit fish later...

In reply to Re: Refactor huge subroutine by grep
in thread Refactor huge subroutine by est

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found