how to get tomorrow date using Date::CALC

PERL

    Next

  • 1. Store a single character AFTER a match
    Hello I'm trying to edit a text file and after my script finishes save that text file. One thing I need to do is save the character AFTER a match into a variable. while (<FILE>){ s/<(Ra|N\d)>//; s!^(.\w\w)( \d+):(\d+)!$1~$2~$3!; if (/<nsup>/) # Then save the character I've tried using the $POSTMATCH variable but it grabs the rest of the line, I only want one character. Also after I execute my replacements how do I save the changes to the text file? while (<FILE>){ s/<(Ra|N\d)>//; s!^(.\w\w)( \d+):(\d+)!$1~$2~$3!; } #save the changes made?? close FILE Thanks, Joe BTW I finally got the correct syntax to open a file! #!/usr/local/bin/perl -w use warnings; use strict; open FILE, '<', 'C:\gen.txt' or die "Could not open file. $!"; while (<FILE>){ s/<(Ra|N\d)>//; s!^(.\w\w)( \d+):(\d+)!$1~$2~$3!; print; } close FILE; Thanks Guys!
  • 2. Except script error
    I am rewriting my Except script from bash to Perl. But i get an syntax error at the Send command. Google is not helping me out here, so i hope for an answer here. Here is a part of the script: #!/usr/bin/perl -w use Expect; $post = "post"; $quit = "quit"; spawn telnet "news.nl-netwerken.com 119"; expect { 200} send "$post\r"; expect { 340} And here is the error: syntax error at ./p line 12, near "send" Execution of ./p aborted due to compilation errors. What is wrong with this line ? Thanks for your time. -- Gr. Ruud news://news.nl-netwerken.com
  • 3. Works great!
    That did the trick. "Michele Dondi" < XXXX@XXXXX.COM > wrote in message news: XXXX@XXXXX.COM ... > On Tue, 11 Jan 2005 23:11:33 GMT, "edgrsprj" < XXXX@XXXXX.COM > > wrote: > > >Is there a way to get Perl to print information on the display screen line > >at the same time that it is generated? > > $|++; > > Michele print 'Thanks '; $|++,; sleep 2; print 'again', "\n"; sleep 2; print 'Thanks '; $|++,; sleep 2; print 'again', "\n"; sleep 2;
  • 4. Advice please on stripping non-printing characters
    Hi! I've seen various examples of stripping non-printing (and non-ascii) chars from a string with something like this: $string =~ s/[\000-\037]/ /g; I've chosen to strip all but the printable ascii chars (using hex): $string =~ s/[^\x20-\x7f]/ /g; This *seems* to work better for my purposes, I'm wondering though if are gotchas I'm missing. Thanks.

how to get tomorrow date using Date::CALC

Postby Bob » Fri, 02 Sep 2005 21:19:42 GMT

want to take a date and return tomorrow's date..
How to convert  $tomorrow back to  YY-MM-DD  format?
What is the inverse of     Date_to_Days ?


.. perl2.pl ---------------------------
use strict;   use warnings;   use Date::Calc qw(:all);

my ($yr2, $mon2, $day2, $tomorrow);   my ($year, $month, $day);
$yr2 = 2005;   $mon2 = 3;   $day2 = 20;

print ("    date- year: $yr2   month: $mon2    day:$day2 \n");
$tomorrow = Date_to_Days($yr2,$mon2,$day2) + 1;
print ("tomorrow: $tomorrow \n");

($year,$month,$day) = Today([$tomorrow]);
print ("tommorow- year: $year   month: $month    day:$day \n");
------------------------------------------------------------------

  output  ------------------------------------
D:\edu\lrn\perl\date>perl date2.pl
    date- year: 2005   month: 3    day:20
tomorrow: 732026
tommorow- year: 2005   month: 9    day:1




Re: how to get tomorrow date using Date::CALC

Postby Paul Lalli » Fri, 02 Sep 2005 21:56:34 GMT



Did you even *try* to look for this answer on your own?  Say, in the
documentation for the function you're using, of the module you're
using?

Straight out of perldoc Date::Calc's Date_to_Days() section :
In order to convert the number returned by this function back into a
date, use the function "Add_Delta_Days()" (described further below), as
follows:

  $days = Date_to_Days($year,$month,$day);
  ($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);

Please make an attempt to help yourself before asking hundreds of
people around the world to read documentation to you.


GAAAH.  What do you have against newlines?


What made you think the Today() function takes a number of days as an
argument?  The docs say:
========================================
# ($year,$month,$day) = Today([$gmt]);

<...>

If the optional (boolean) input parameter "$gmt" is given, a "true"
value ("1") will cause "gmtime()" to be used instead of "localtime()",
internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of
local time.
=======================================

Nothing about this function says that it returns anything other than
*today*'s  date.

Paul Lalli


Similar Threads:

1.RFC: Date::Extract::P800Picture - gets YMDH encoded date from image filename

2.Date::CalC

Hi, 

Could someone take a look at the code for me below and see if you can figure out what's wrong with it? I just want to evaluate $publish_date to see if it's with 21 days of the current date; if so then set $new_item=" True". Not sure why it's not doing that, I think the it's not evaluating the if statement. I do have Date::CalC installed. Thanks.  

"if (my ($year1,$month1,$day1) = Decode_Date_US($mmddyyy))". 


#!/usr/bin/perl
use strict;
use warnings;

sub NewProducts
  {

 use Time::localtime;
 use Time::Local;
 use Date::Calc qw(:all);

  # Create date property in format mmddyyyy
  # for input to Decode_Date_US() function below
  my $publish_date = "01/02/2009 12:32:03 PM";
  my $mmddyyyy = substr($publish_date, 5, 2);
  $mmddyyyy .= substr($publish_date, 8, 2);
  $mmddyyyy .= substr($publish_date, 0, 4);
        if (my ($year1,$month1,$day1) = Decode_Date_US($mmddyyyy))
                {
                my ($year2,$month2,$day2) = Today();
                my $delta = Delta_Days($year1, $month1, $day1, $year2, $month2, $day2);
                if($delta <= 21 && $delta >= 0)

                        {
                          my $new_item = "True";
                          
                        }
                
                }
   
  } #End of sub

&NewProducts();



      

3.Converting military time with Date::Calc

Hi...does anyone know how or what module I could use to convert a 
standard time format like '12:00:00' to military time say '24:00:00'. I 
guess I could write a module of sorts to do this task but am lazy and 
thought there might be a SPECIFIC module to do this. Date::Calc doesn't 
seem to have anything that might do it.

Schmidty

4.Date:Calc and Bit::Vector compilation problems on 64 but linux

5.adding the date::calc module

6. Problem with Module Date::Calc

7. Installing Date::Calc

8. Date::Calc Problem



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 38 guest