Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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?

script.pl --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 );

Output:

$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.


Comment on Re: dynamic regex
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-09-20 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls