note
jwkrahn
<blockquote><i><c>
my $cnt = 0;
...
$cnt++;
...
print $cnt, "\n";
</c></i></blockquote>
<p>
You don't really need the <c>$cnt</c> variable. Just remove the first two lines and change the last line to:
</p>
<c>
print "$.\n";
</c><br /><br />
<blockquote><i><c>
my $filename = '$mainDir\test.txt';
</c></i></blockquote>
<p>
Variables don't interpolate in single quoted strings so you should change that to a double quoted string:
</p>
<c>
my $filename = "$mainDir\test.txt";
</c><br /><br />
<blockquote><i><c>
my $mth_end = sprintf "%04d,%02d,%02d",$y,$m,Days_in_Month($y,$m);
</c></i></blockquote>
<p>
You never use <c>$mth_end</c> anywhere.
</p><br /><br />
<blockquote><i><c>
printf OUT " Placement Release Tot Chg\n";
printf OUT " Date Date Days Days Cost\n";
</c></i></blockquote>
<p>
You should be using [doc://print] instead of [doc://printf]:
</p>
<c>
print OUT " Placement Release Tot Chg\n";
print OUT " Date Date Days Days Cost\n";
</c><br /><br />
<blockquote><i><c>
my @dates = split '\s+', $_;
</c></i></blockquote>
<p>
Or just:
</p>
<c>
my @dates = split;
</c><br /><br />
<blockquote><i><c>
if ($free >= 0) {
my $amt = $free;
my $cost = ($amt * 100);
my $pfmt = "%-14s %-5s %-8s %-3s %-12s %-12s %-6s %-6s %-6s\n";
printf OUT $pfmt, $dates[0], $dates[1], $dates[2], $dates[3], fmt_mdy($dates[4]), fmt_mdy($dates[5]), $diff, $amt, fmt_curr($cost);
}
elsif ($free < 0) {
my $amt = 0;
my $cost = ($amt * 100);
my $pfmt = "%-14s %-5s %-8s %-3s %-12s %-12s %-6s %-6s %-6s\n";
printf OUT $pfmt, $dates[0], $dates[1], $dates[2], $dates[3], fmt_mdy($dates[4]), fmt_mdy($dates[5]), $diff, $amt, fmt_curr($cost);
}
</c></i></blockquote>
<p>
You have a lot of code duplication in there. You could simplify that as:
</p>
<c>
my $amt = $free < 0 ? 0 : $free;
my $cost = $amt * 100;
my $pfmt = "%-14s %-5s %-8s %-3s %-12s %-12s %-6s %-6s %-6s\n";
printf OUT $pfmt, @dates[ 0, 1, 2, 3 ], fmt_mdy( $dates[ 4 ] ), fmt_mdy( $dates[ 5 ] ), $diff, $amt, fmt_curr( $cost );
</c><br /><br />
<blockquote><i><c>
$ymd =~ s/ //g;
# return ' 'x10 if $ymd eq $NULL_DATE;
my ($y,$m,$d) = split /\D/,$ymd;
</c></i></blockquote>
<p>
<p>
Why remove spaces when they match <c>/\D/</c> which your [doc://split] will remove anyways? The problem is that <c>split /\D/,$ymd</c> will only remove single non-digit characters and you need to remove multiple non-digit characters:
</p>
<c>
my ( $y, $m, $d ) = split /\D+/, $ymd;
</c>
<p>
Or just capture the digit characters:
</p>
<c>
my ( $y, $m, $d ) = $ymd =~ /\d+/g;
</c><br /><br />
<blockquote><i><c>
while (<$file>) {
...
sub fmt_curr {
...
sub fmt_mdy {
...
}
</c></i></blockquote>
<p>
Subroutine names are available globally so putting them inside a while loop does not effect their scope, but it might complicate the use of variables inside the subroutine.
</p>
1049334
1049334