By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Modifying Date value in this short script

P: 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
Share this Question
Share on Google+
1 Reply


Ganon11
Expert 2.5K+
P: 3,652
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.