From: zilore mumba <zmu...@yahoo.com>
To: "Thurn, Martin (TASC)" <martin.th...@tasc.com>
Sent: Monday, April 30, 2012 10:29 PM
Subject: Re: help regex replacement

My mail should have read
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 1st 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.

sample output
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',


From: "Thurn, Martin (TASC)" <martin.th...@tasc.com>
To: zilore mumba <zmu...@yahoo.com>
Cc: "Thurn, Martin (TASC)" <martin.th...@tasc.com>
Sent: Monday, April 30, 2012 7:45 PM
Subject: RE: help regex replacement

1.  Reduce your sample program to the MINIMUM amount of code that reproduces your problem.  Especially, get rid of all file-open-read-write and get rid of looping. 
2.  Include some sample INPUT data (and clearly indicate).
3.  Include some sample desired OUTPUT data (and clearly indicate).
4.  What is your intention when writing “start_date .._00” in your regex?  I think you don’t understand what “.” means in a regex. 
5.  What is your intention when writing “end_date * _00” in your regex?  I think you don’t understand what “*” means in a regex. 
 
 
 - - Martin
 
From: activeperl-boun...@listserv.activestate.com [mailto:activeperl-boun...@listserv.activestate.com] On Behalf Of zilore mumba
Sent: Monday, April 30, 2012 13:15
To: activeperl@listserv.activestate.com
Subject: help regex replacement
 
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.
Image removed by sender.
CONFIDENTIALITY NOTICE: This message and any attachments or files transmitted with it (collectively, the "Message") are intended only for the addressee and may contain information that is privileged, proprietary and/or prohibited from disclosure by law or contract. If you are not the intended recipient: (a) please do not read, copy or retransmit the Message; (b) permanently delete and/or destroy all electronic and hard copies of the Message; (c) notify us by return email; and (d) you are hereby notified that any dissemination, distribution or copying of the Message is strictly prohibited.




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

Reply via email to