469,336 Members | 6,245 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Modifying Date value in this short script

1
Hello, I'm a bit new to Perl so I was hoping someone with experience could give me a quick answer.

Question: The following script changes the date from today's date to (today's date+6 months). How do i change that value to 2 or 3 months instead?

Thanks!
Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl -w
  2.  
  3. use strict;
  4. use Date::Calc qw( Delta_Days Add_Delta_Days Today Month_to_Text );
  5.  
  6. my $TAC_FILE = "$ENV{HOME}/tacacs/common/user_accounts";
  7.  
  8. my ($year, $month, $day) = Add_Delta_Days(Today(), 30);
  9.  
  10. my $m = substr(Month_to_Text($month),0,3);
  11.  
  12. my $expire_date =  "$m $day $year";
  13.  
  14.  
  15.  
  16. open(TACFILE, "$TAC_FILE") || die "Can't open $TAC_FILE file\n";
  17.  
  18. while(<TACFILE>) {
  19.  
  20.    if (/^\s+member\s+=\s+\S+\s+$/) {
  21.       s/^(\s+)(member\s+=\s+\S+)/$1$2\n$1expires = "$expire_date"/
  22.    }
  23.  
  24.    print $_;
  25. }
  26. close(TACFILE);
  27.  
Sep 16 '08 #1
1 1826
Ganon11
3,652 Expert 2GB
Not being completely familiar with all the modules used here, it still looks like the Add_Delta_Days function is only adding 30 days to Today(), which is approximately 1 month. You can try changing the value in Add_Delta_Days, or see if there's another function in Date::Calc like Add_Delta_Months.
Sep 16 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Tim Conkling | last post: by
4 posts views Thread by Jo | last post: by
6 posts views Thread by MickG | last post: by
4 posts views Thread by rzhang | last post: by
10 posts views Thread by John Morgan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.