what is lwp?
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
Jay Savage
<[EMAIL PROTECTED]
l.com> To
"[EMAIL PROTECTED]"
06/23/2005 02:16 <[EMAIL PROTECTED]>, Perl
PM Beginners List <[email protected]>
cc
Please respond to Subject
Jay Savage Re: date range....
<[EMAIL PROTECTED]
l.com>
On 6/23/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> People of the Perl,
>
> I have a need to develop some logic to automatically pick up a publc key
> for my gpg keyring. I will use cURL ( client for URL lookups ) language
> for the actual download , but the catch is the expiration time of our key
> which is 2005-11-16. So I want to say if calc data =~ current date then
> call cURL.
> I tried an ascii increment but this only incremented from 2005-06-23 to
> 2006. Maybe I am going about this all wrong???
> My like operator really needs to say + - 7 days from 2005-11-16 then call
> cURL and check for a new public key.
>
> Here is my code:
>
>
> require 5.8.0;
> use strict;
> use warnings;
>
> # for talx expiration date of their pubkey 2005-11-16
>
> our $time = $^T;
> $ENV{"PATH"} =
> qq(/home/gpghrp/.gnupg/scripts:/usr/local/bin:/bin:/usr/bin);
>
>
> ##--## Begin Routines ##--##
>
> sub dateme
> {
> my ($year,$month,$day) = (localtime)[5,4,3];
> sprintf ("%04d-%02d-%02d\n", ($year += 1900),
> $month+1,$day);
> }
> my $curtdate = &dateme();
> #print $curtdate,"\n";
>
> sub date_manip_fwd_6mths
> {
> use constant ONE_DAY => 86400;
> use constant THIRTY_DAYS => ONE_DAY * 30;
> use constant SIX_MTHS => THIRTY_DAYS * 5;
> my $days = (shift);
> my ($y,$m,$d) = (localtime($time + $days)) [5,4,3];
> sprintf ("%04d-%02d-%02d", ($y += 1900), $m+1,$d);
> }
>
> my $calcdate = &date_manip_fwd_6mths(SIX_MTHS);
> #print $calcdate,"\n";
> #my $calcdate = &date_manip_fwd_6mths();
>
>
> ##--## Main ##--##
> print "$calcdate\n$curtdate";
> if ( $calcdate eq $curtdate ) {
> print "YES\n";
> print "$calcdate\n$curtdate";
> }
>
> __END_CODE__
>
> __BEGIN_DATA__
>
> 2005-11-20
> 2005-06-23
Derek,
Check out Date::Calc. I'd do somthing like this:
#!/usr/bin/perl
use warnings;
use strict;
use Date::Calc qw(Delta_Days);
my $target = "2005-11-16";
my ($nowyr, $nowmo, $nowday) = (localtime)[5,4,3];
my ($taryr, $tarmo, $tarday) = split /-/, $target;
my $diff = Delta_Days($nowyr + 1900, $nowmo, $nowday, $taryr,
$tarmo, $tarday);
if ( abs($diff) <= 7 ) {
system("curl", "args");
# but why not use lwp?
}
HTH,
-- jay
--------------------
daggerquill [at] gmail [dot] com
http://www.tuaw.com
http://www.dpguru.com
http://www.engatiki.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>