Ankit Gupta wrote at Fri, 24 May 2002 17:13:52 +0200: > Hello, > > I am working on a project in which I need to get Date part of > below written header. I am trying to use Regular expression to extract Date: line. I >am able to > achieve everything after the Date: word but not only that line. I mean to say that I >need only > this string Thu, 23 May 2002 19:47:50 +0530 . Can someone help me in this. I am >trying > $header =~ m/Date:/; and then my $ab = " $' \n"; but this gives me > everything after Date: word. As I wrote above, I need only Thu, 23 May 2002 19:47:50 >+0530 string > > To: "Ankit Gupta" <[EMAIL PROTECTED]> > References: <[EMAIL PROTECTED]> ><001c01c200e0$9a1d9720$7d82c8cb@ashokgup> > <[EMAIL PROTECTED]> > Subject: Re: > Date: Thu, 23 May 2002 19:47:50 +0530 > MIME-Version: 1.0 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: 7bit > X-Priority: 3 > X-MSMail-Priority: Normal > X-Mailer: Microsoft Outlook Express 5.00.2615.200 > X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Return-Path: >[EMAIL PROTECTED] >
One way to get it is: my $date = (map {/^Date: (.*)/} grep {/^Date:/} split "\n", $header )[0] or when you use List::Util qw(first) first {/^Date:/ (.*)} split ("\n", $header); my $date = $1; but surely the BEST method will be to use an already existing module: Mail::Header my $header_obj = Mail::Header->new([split "\n", $header]); my $date = $header_obj->get('Date'); Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]