Help - Search - Member List - Calendar
Full Version: date range....
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
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-%02dn", ($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 "$calcdaten$curtdate";
if ( $calcdate eq $curtdate ) {
print "YESn";
print "$calcdaten$curtdate";
}

__END_CODE__

__BEGIN_DATA__

2005-11-20
2005-06-23




Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams


Jay Savage
On 6/23/05, [Email Removed] <[Email Removed]> wrote:
QUOTE
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-%02dn", ($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 "$calcdaten$curtdate";
if ( $calcdate eq $curtdate ) {
print "YESn";
print "$calcdaten$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

Chris Devers
On Wed, 29 Jun 2005 [Email Removed] wrote:

QUOTE
what is lwp?

Try Google.

<http://www.google.com/search?q=lwp>

Most or all of the top 20 hits are related to Perl's LWP.

Search for 'lwp perl' and nearly all the top 50 hits are right.

<http://www.google.com/search?q=lwp+perl>

I think that makes this a Frequently Answered Question :-)



--
Chris Devers

what is lwp?

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams





Jay Savage
<daggerquill@gmai
l.com> To
"[Email Removed]"
06/23/2005 02:16 <[Email Removed]>, Perl
PM Beginners List <[Email Removed]>
cc

Please respond to Subject
Jay Savage Re: date range....
<daggerquill@gmai
l.com>








On 6/23/05, [Email Removed] <[Email Removed]> wrote:
QUOTE
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-%02dn", ($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 "$calcdaten$curtdate";
if ( $calcdate eq $curtdate ) {
print "YESn";
print "$calcdaten$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 Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Jay Savage
On 6/29/05, Chris Devers <[Email Removed]> wrote:
QUOTE
On Wed, 29 Jun 2005 [Email Removed] wrote:

what is lwp?

Try Google.

<http://www.google.com/search?q=lwp

Most or all of the top 20 hits are related to Perl's LWP.

Search for 'lwp perl' and nearly all the top 50 hits are right.

<http://www.google.com/search?q=lwp+perl

I think that makes this a Frequently Answered Question :-)



--
Chris Devers


In paricular, check out LWP::Simple's get() function wich is
functionally equivalent to a bare call to curl, but doesn't require
the system() invokation.

Far more useful in a script, too, since it returns the data, which is
usually what you want. (think '$something = `curl [args]`'). Of
course, if you don't want to do anything with the returned data,
getstore() and getprint() are provided as well.

And while google is helpful, I highly recommend 'apropos lwp', which
on most systems will return the extremely useful descriptions:

LWP (3pm) - The World-Wide Web library for Perl
LWP::Simple (3pm) - simple procedural interface to LWP


From there 'perldoc LWP' or 'man LWP' will get you on your way. If
none of this is sounding familiar, though, I might reccommend a basic
guide for your OS of choice, in addition to whatever Perl tutorials
you're using.


-- jay
--------------------
daggerquill [at] gmail [dot] com
http://www.tuaw.com
http://www.dpguru.com
http://www.engatiki.org


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.