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

Re: dynamic regex

by Kenosis (Priest)
on Dec 04, 2012 at 03:59 UTC ( #1006989=note: print w/replies, xml ) Need Help??

in reply to dynamic regex

I agree with graff about using a Date:: module. How would you create the end given this start? --start 'Dec 31 23:59'

Consider the following:

use strict; use warnings; use Date::Parse; use Date::Calc qw/Localtime/; my $startDateTime = 'Dec 31 23:59:'; my $addMinutes = 2; my $year = ( Localtime(time) )[0]; $startDateTime .= '00 ' . $year; my $startSeconds = str2time($startDateTime); my $endSeconds = $startSeconds + $addMinutes * 60; print "\$startSeconds: $startSeconds; \$endSeconds: $endSeconds; Delta +: " . ( $endSeconds - $startSeconds );


$startSeconds: 1357027140; $endSeconds: 1357027260; Delta: 120

You can use Date::Parse to convert a line's date/time string to seconds, and then print the line if the value's within the $startSeconds and $endSeconds range.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006989]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2016-10-25 16:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (325 votes). Check out past polls.