in reply to hash, Date:Calc use - seeking improvements
Firstly, a personal preference: I hate seeing all variables declared at the top. Declare them as you use them.
The second thing that strikes me in your code is your declaration of your hash. You don't need to assign any value at all. Something like my %hash; works perfectly. Or if you prefer: my %hash = ();. That way you won't have to delete the key later.
Then there's no need to use @old as your <DATA> file handle can work inside the foreach:
Also your cvrt_mon_lcl subroutine would be better as a hash:foreach $old(<DATA>) { ... }
Back to all those modules to select from, I'm a DateTime fan (and developer) so I'll give you my DateTime solution:my %month_number; @month_number{qw/Jan Feb Mar Apr May ... Dec/} = (0 .. 11); print $month_number{Jan}; # 0
Some notes:use DateTime; use DateTime::Format::Strptime; my $parser = DateTime::Format::Strptime->new( pattern => '%a %b %d %T EST %Y', # see the docs for the patterns locale => 'en_US', # to get the month and day names to parse time_zone => 'America/New_York', ); my $now = DateTime->now(time_zone => 'America/New_York'); foreach (<DATA>) { my ($dt) = $_ =~ /^(.+?)\s:\s/; $dt = $parser->parse_datetime($dt); # turn the string into a dateti +me print $_ if (($dt < $now) and ($dt->add(days => 45) > $now)) } __DATA__ Fri Dec 3 23:07:21 EST 2004 : Depth is : 234 Sat Dec 4 00:07:29 EST 2004 : Depth is : 123 Sun Dec 5 03:07:32 EST 2004 : Depth is : 144 Tue Feb 8 05:21:18 EST 2005 : Depth is : 11 Sat Feb 26 14:13:12 EST 2005 : Depth is : 4567 Fri Mar 11 17:09:38 EST 2005 : Depth is : 265 Sat Mar 12 07:07:27 EST 2005 : Depth is : 1654 Sat Mar 26 07:07:27 EST 2005 : Depth is : 1654
|
|---|