On Wed, May 25, 2011 at 07:39:28 -0700 , Irfan Sayed wrote:
> hi,
> 
> i have string like this
> "2011/05/25 07:24:58 -0700 PDT"  i need to match "2011/05/25"
> i wrote reg ex like this: ^\d\d\d\d//\d\d/\d\d$ but it is not working 
> 
> code is like this 
> 
> 
> $lin = "2011/05/25 07:24:58 -0700 PDT";
> $lin =~ m/^\d\d\d\d//\d\d/\d\d$/;
> print "$lin\n";
> 
> plz suggest 

I suggest you look at the POSIX::strptime module and function. If you're
familiar with strptime(3), it provides that interface for parsing dates
and times. For example, you could parse your dates like so:

POSIX::strptime("2011/05/25 07:24:58 -0700 PDT", "%Y/%m/%d")

There are other formats for matching the time, the UTC timezone offset,
and the timezone name. But the example given should get you started.

Additionally, if you're doing lots of date/time manipulation, consider
DateTime.pm and DateTime::Format::Strptime, which uses strptime(3) to
create DateTime objects.

-- 
Chris Nehren           | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to