"Andrew Gaffney" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> R. Joseph Newton wrote:
> > Andrew Gaffney wrote:

[snip]

> I didn't do it this way because there is a "first" pay period. If there
are only 2 pay
> periods from the starting date, you can't build a list of 6. My way takes
that into
> account. Below is the modified code based on (most of) your suggestions.
>
> use constant PAY_PERIOD_DAYS => 14;
> my @pay_periods;
> my @final_pay_periods;
> my $last_period_end = Date::Simple->new('2004-03-20');


> my @lt = localtime;
> my $today = Date::Simple->new($lt[5]+1900, $lt[4]+1, $lt[3]);

Here you could just say:

    my $today = Date::Simple->new;


> while($today > $last_period_end + 1) {
>    my $new_start = $last_period_end + 1;
>    my $new_end = $last_period_end + PAY_PERIOD_DAYS;
>    push @pay_periods, "$new_start to $new_end";

You can make the list ordered from most recent period to least recent
by saying:

    unshift @pay_periods, "$new_start to $new_end";


>    $last_period_end = $new_end;
> }


        > my $period_counter = 0;
        > foreach(reverse @pay_periods) {
        >    $period_counter++;
        >    last if($period_counter > 6);
        >    push @final_pay_periods, $_;
        > }

Not necessary to do the above, but need this statement to
limit @pay_periods to most recent 6 periods (if there are 6)

    splice @pay_periods, 6 if @pay_periods > 6;


HTH,
Chris



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to