On Wed, Aug 13, 2008 at 10:05 AM, John W. Krahn <[EMAIL PROTECTED]> wrote:

Kashif Salman wrote:

Greetings,


Hello,

 I have a log file like so, and I am trying to get the date on the next
line
after "Start..." line. So for the log below I'd like to get the output

04/06/05
05/06/05
06/06/05

But I also need to re-format that so the end result becomes:

2005-04-06
2005-05-06
2005-06-06

Any hints?


while ( <> ) {
   /^Start/ && <> =~ /^(\d+)\/(\d+)\/(\d+)/ && print "20$3-$1-$2";
   }


John


 /^Start/ && <> =~ /^(\d+)\/(\d+)\/(\d+)/ && print "20$3-$1-$2";


I understand most of what is going on in the above line except the " && <> "
part. Can somebody please explain that? Somehow it searches for "Start" in
the beginning of the line and gets the date from the next line.


The <> operator is in scalar context, so it reads the next line (after Start) *and* performs a match on that line. In the match, it captures 3 groups of your date digits and, if the match succeeds, prints them out in the form yyyy-mm-dd.

$1 is the first captured digits, $2 is the second capture, etc.

Hope this helps,
Chris


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


Reply via email to