Encountered another problem:

I'm trying to use a calculated date value in a regex. It only works with 
values which are NOT calculated.
                my ($dc, $mc, $yc) = (localtime(time))[3,4,5];
                             my $date_now = sprintf("%02d-%02d-%02d", $dc, $mc+1, 
$yc-100);
                
                my ($da, $ma, $ya) = (localtime (time + (ONE_DAY)))[3,4,5];
                                my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, 
$ya-100);

using $date_now in this regex works:
                        while (<APODATA>) {
                                ( $date_today, $aponame, $apoaddress, $apotel) = 
split(/:/,$_);
                                        my @data = split(/:/);
                                                foreach ($data[0]) {
                                                        if (/$date_now/) {             
 
                                                                print "$date_now\n";
                                                                print "$next_date\n";
                                                                                   }
                                                                                }

if I replace $date_now with $next_date I get an error message (premature 
end of script headers).

Does anybody know how?

Thanks for your tips in advance.

Sven
                
                        
On Tuesday, May 28, 2002, at 07:53 PM, drieux wrote:

>
> On Tuesday, May 28, 2002, at 09:25 , Sven Bentlage wrote:
>
>> Hi !
>> I'm trying to get all the date values for the week (7days) ahead of a 
>> specified date.
>> To get the current date I use :      
>>                                              my ($d, $m, $y) = (localtime)[3,4,5];
>>                                              my $date = sprintf("%02d-%02d-%02d", 
>$d, $m+1, $y-100);
>> To get the date of the date 7 days ahead I use:
>>                                              my ($da, $ma, $ya) = (localtime (time+ 
>(7*24*60*60)))[3,4,5];
>>                                              my $next_date = 
>sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>
>
> your friend the loop would help here.
>
>       use constant SECONDS_PER_DAY    (24*60*60);
>
>       my $day_ahead = 1;
>       my $max_day_ahead = 7;
>
>       for (; $day_ahead <= $max_day_ahead ; $day_ahead++ )
>       {
>               my $tmp_t =( $day_ahead * SECONDS_PER_DAY);
>               my ($da, $ma, $ya) = (localtime(time + $tmp_t))[3,4,5];
>               my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>               ....    
>       }
>
>
> you may want to do the perldoc on constant - since this
> will help you with more on how to think about writing
> self documenting code....
>
> ciao
> drieux
>
> ---
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to