This is a quick refactoring of your _get_list function. It's not guaranteed to work (it's untested) and it could use more refactoring, but it gives you the idea of what's going on. What I've done is move duplicate code into its own subroutine and taken code unrelated to the actual function and moved it into a subroutine that is (as far as I can tell) descriptively named. This makes the logic of the _get_list function much cleaner and easier to read.

Again, this is only a rough start, but it gives you an idea of where to go from here. Note that the actual logic of _get_list has been altered slightly so as to avoid a bit of duplication.

sub _get_list { my ($date, $report_dir, $config_dir, $hours) = @_; my %reports; if ($hours == 0) { %reports = _sum_report_entries($config_dir, 'report_master_list'); } else { %reports = _sum_report_entries($config_dir, 'report_temp_list'); if ($hours == 8) { _write_non_transferred_reports( %reports ); unlink "$config_dir/report_temp_list" or warn "$!"; return; # this *seems* to duplicate the logic! } _get_reports($date, $report_dir, $config_dir, \%reports); } sub _write_non_transferred_reports { my %reports = @_; open OUT, ">> /disk2/daily_report" or die "$!"; print OUT "\n\nDaily Reports That Were Unable To Be Transferred\n"; print OUT "------------------------------------------------\n\n"; for my $report (sort keys %reports) { print OUT "$report\n"; } print OUT "\n\n"; close OUT; } sub _sum_report_entries { my ($config_dir,$list_file) = @_ my $report = "$config_dir/$list_file"; my %sums; open REPORT, "<", $report or die "Cannot open ($report) for reading: + $!"; while ( chomp (my $line = <REPORT>) ) { $sums{$line}++; } close REPORT or warn "Cannot close ($report): $!"; return %sums; }

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)


In reply to Re: Code Review by Ovid
in thread Code Review by PrimeLord

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.