T add a bit more precision, the lines must appear as they are because the 
program which reads the file will look for "start_date=followed by the date". I 
was looking, in perl, for something like "replace line starting in, say 
/^start_date .. and ending in ...'2012-04-29_00:00:00',$/
I hope this is possible.
Zilore



________________________________
 From: zilore mumba <zmu...@yahoo.com>
To: $Bill Luebkert <dbec...@roadrunner.com> 
Cc: "activeperl@listserv.ActiveState.com" <activeperl@listserv.ActiveState.com> 
Sent: Tuesday, May 1, 2012 5:31 AM
Subject: Re: help regex replacement
 

Thanks very much Bill, and also for the assistance to me over the years. Your 
suggestion does not do exactly what I want to do. The start_date and end_date 
are in a file, in the middle of other text. The idea is to replace daily the 
year,month and day to the current year,month and dayand on end_date to replace 
to tomorrow or after tomorrow, The fields may appear twice or yhree times 
because the model has nests in it which all use the same times.
I hope this is clear.



________________________________
 From: $Bill Luebkert <dbec...@roadrunner.com>
To: zilore mumba <zmu...@yahoo.com> 
Cc: "activeperl@listserv.ActiveState.com" <activeperl@listserv.ActiveState.com> 
Sent: Tuesday, May 1, 2012 12:02 AM
Subject: Re: help regex replacement
 
On 04/30/2012 14:28, zilore mumba wrote:
> sample input
> start_date = 
> '2012-04-29_00:00:00','2012-04-29_00:00:00','2012-04-29_00:00:00',
> end_date = '2012-05-01_00:00:00','2012-05-01_00:00:00','2012-05-01_00:00:00',
>
> The model would have run on 29th May, to produce a 48hour forecast to 1sr May 
> 2012.
>> When I run it on 30th May it should produce a 48hour forecast to 2nd May, 
>> i.e. change the entries above so that start_date is 30th and end_date is 2nd 
>> May as below.

> start_date = 
> '2012-04-30_00:00:00','2012-04-30_00:00:00','2012-04-30_00:00:00',
> end_date = '2012-05-02_00:00:00','2012-05-02_00:00:00','2012-05-02_00:00:00',
>
> zilore mumba schrieb am 30.04.2012 um 10:14 (-0700):
>  > I have to automate a modle namelist by replacing the start and end
>  > date of the model run as per lines below.

I have no idea where this data is or what you are
 doing, but it's an easy matter
to take a date and add 86400 to it and format it back out again.

use strict;
use warnings;
use POSIX;
use Time::Local;

# assuming you have this data in $start_date:
my $start_date = '2012-04-29_00:00:00';

# and you want to add 1 day to it

# just get date portion because the time doesn't appear to be used (always == 0)
# you could split on _ and work both date and time if needed
(my $date = $start_date) =~ s/_.*$//;

# OK, now convert it to epoch time
my @D = split /-/, $date;
# OK, we now have the year, month and day in @D

# let's convert it to epoch (you could use timegm if UTC time rather than local)
# I'm hard coding the time to 0 per example
my $epoch = timelocal 0, 0, 0, $D[2], $D[1]-1, $D[0]-1900;

# now let's add a day to it
$epoch += 86400;

# OK, all done, let's format a new date-time string
my @tm = localtime
 $epoch;    # get it back from epoch to its pieces
my $new_start_date = strftime "%Y-%m-%d_%H:%M:%S\n", @tm;    # format it

print "start_date=$start_date, new start_date=$new_start_date\n";

__END__



_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to