Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Answer: Fast(er) date parsing

( #23311=categorized answer: print w/ replies, xml ) Need Help??

Q&A > dates and times > Fast(er) date parsing contributed by fundflow

Thanks guys, maybe i wasn't clear. I want to get the unix timing (since epoch) from the data and was wondering if there is an inverse function to strftime(). I just realized that its not that hard and so here is my solution, following lhoward's suggestion:
use Time::Local; my %months = ( Jan=> 0, Feb=> 1, Mar=> 2, Apr=> 3, May=>4, Jun=> 5, Jul=> 6, Aug=> 7, Sep=> 8, Sep=> 8, Oct=> 9, Nov=> 10, Dec= +> 11); # Parse the date: Fri Jun 30 11:07:39 2000 my ($day, $month, $mday, $time, $year)=split(" ", $d); my ($hour,$min,$sec)=split(":",$time); my $result = timelocal($sec,$min,$hour,$mday,$months{$month},$year);

I'd prefer not having to use any module but this seems reasonable
The reason i need this is to go through some log files and print a summary of the events that happened in the past 24 hours.

Comment on Answer: Fast(er) date parsing
Download Code
Replies are listed 'Best First'.
Re: Answer: Fast(er) date parsing
by I0 (Priest) on Dec 29, 2000 at 17:34 UTC
    If you just want to check if the event was in the last 24 hours without using any module, you could compare
    my @yesterday=localtime time-24*60*60; if( (sprintf"%02d"x6, $yesterday[5]+1900,@yesterday[4,3,2,1,0]) < (sprintf"%02d"x6, $year,$months{$month},$mday,$hour,$min,$sec) )
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2015-07-08 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (95 votes), past polls