Your code is incredibly long for something that looks pretty simple, if I understand it correctly.
You haven't described your files, but I assume that the three first columns, put together, define a unique identifier for the tasks you want to process.
You first need to read the first file and store in a hash the 3-day gratuity left-overs. Something like this (untested):
my %free_days_left;
while (<$file1>) {
chomp;
my @fields = split /\s+/, $_;
my $key = join "-", @fields[0..2];
$free_days_left{$key} = $fields[5];
}
This could be made more compact, but I prefer just to explain the process as clearly as possible.
Now, the %free_days_left hash contains the free days left. You just need to read through the second file, compute the number of days, subtract the free days and output the result (again, a general idea, not tested).
while (<$file2>) {
chomp;
my @fields = split /\s+/, $_;
my $key = join "-", @fields[0..2];
my ($start_date, $end_date) = @fields[5,6];
my $start_day = (split /,/, $start_date)[2];
my $end_day = (split /,/, $end_date)[2];
my $duration = $end_day - $start_day + 1:
my $corrected_duration = exists $free_days_left{$key}? $duration
+- $free_days_left{$key} : $duration;
print $file3 join " ", $_, $duration, $corrected_duration, $corre
+cted_duration * $unit_price, "\n";
}
OK, the formating of the output file may need a bit more work, but I guess you've got the basic idea.
-
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.