Nice job, thinks are looking more answerable already
Ok, here is the next step, start making functions :)
Functions with meaningful names
For an example see Re^6: Help with locating bp region in chromosome
You would turn each loop into a separate function, so you end up with something like
...
Main( @ARGV );
exit( 0 );
sub Main {
...
my ( $allPronouns, $allMatches ) = MeaningfulMatches( \@parsed );
my $PronounCountsHashref = CountPronouns( $allPronouns );
my $CountsHashref = CountMatches( $all_matches );
SortThisMotherReference( $CountsHashref, $allMatches );
SortThisMotherReference( $PronounCountsHashref, $allPronouns );
...
}
See, isn't that easier to read? And see how the meaningful function names replace some of the comments?
Now that you've got things separated into functions, its easy to use test and tweak each part individually without worrying about the whole thing working, until you've got it producing the correct output.
So the next step is to make sure each function does its job by writing tests for each function. You give it input, it gives you output (or it modifies your input), and you compare the two to see if they match. You can use Test::Deep for this.
Once they match, you move on to the next function
Oh you say CountPronouns() is doing an inaccurate count? Or SortThisMotherReference() is not sorting correctly?
Now its easy to write a small test program. Use Data::Dumper to create sample input, modify it by hand until you have sample output, and then modify the function until it produces the same output.
For another example see Re^3: SEO Fixer Part II - Updated or watch this ~14min video String Calculator TDD Kata done in Perl of a programmer doing this live :) |