Hello Kind folks,
I have to automate a modle namelist by replacing the start and end
date of the model run as per lines below.

start_date = '2012-04-26_00:00:00','2012-
04-26_00:00:00',
end_date   = '2012-04-26_09:00:00','2012-04-26_09:00:00',

I have been checking the documentation on how to te replace a regex
starting with "^x" and ending in $y", no success.
I tried as below:

 my @now = localtime;
 my $shour = strftime "%H",@now;
 my $sday = strftime "%d",@now;
 my $smonth = strftime "%m",@now;
 my $syear = strftime "%Y",@now;

 my ($eday, $emonth, $eyear) = (localtime (time() + 172800)) [ 3,4,5 ];
 $eyear = sprintf( "%04d", $eyear + 1900 );
 $emonth = sprintf( "%02d", ++$emonth);

 open (IN, "<$in_fn") or die "open '$in_fn: failed $! ($^E)";
  my @fields = <IN>;
  close IN;
for (@fields)
    {
     s/^start_date .._00:00:00',$/start_date =
'${syear}-${smonth}-${sday}_00:00:00','${syear}-${smonth}-${sday}_00:00:00',
     '${syear}-${smonth}-${sday}_00:00:00',/g;
      exit;

     s/^end_date * _00:00:00',$/end_date =
'${eyear}-${emonth}-${eday}_00:00:00','${eyear}-${emonth}-${eday}_00:00:00',
     '${eyear}-${emonth}-${eday}_00:00:00',/g;
    }
  open (OUT, ">$out_fn") or die "open '$out_fn: failed $! ($^E)";
   print OUT "@fields\n";
  close OUT;

Does such a way of replacing exist?
Help will be appreciated.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to