pietyc has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to use the Date:Calc function and I am not sure if I am using it correctly. Below is the error I
get when I try to use it and below that is the code that i entered. DO I have to define the variables $days somewhere or does Date:Calc take care of that for me? Thanks for any help, I am on a step learning curve!
charles/2004_ruc2> ./date_calc_test.pl syntax error at ./date_calc_test.pl line 5, near "$days " Execution of + ./date_calc_test.pl aborted due to compilation errors.
#!/usr/bin/perl use Date::Calc qw(:all) $days = Date_to_Days($year,$month,$day); ($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1); print "$days\n";

edited: Tue Mar 9 16:52:22 2004 by jeffa - code tags, formatting

janitored by ybiC: Retitle from "Date:Calc". One-word titles are bad, very bad.</rainman>

Replies are listed 'Best First'.
Re: Date:Calc
by jrsmith (Pilgrim) on Mar 09, 2004 at 14:50 UTC
    You need a semicolon after use Date::Calc qw(:all)

    Also, in your Add_Delta_Days statement, 1,1,1 is not a valid date.
Re: Date:Calc
by dragonchild (Archbishop) on Mar 09, 2004 at 14:51 UTC
    You forgot a semi-colon at the end of your second line. That's what the syntax error is.

    As for your questions - read Learning Perl. What you say indicates a very low understanding of Perl syntax.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      thank you Dragonchild, my face is red....I am busted, I'm a
      chemist trying to learn Perl after work. I have a
      started reading Learning Perl...clearly not close enough.
      A juorney of a thousand miles starts with one step.
      Thanks for guiding me back on the path.
Re: Date:Calc
by Prior Nacre V (Hermit) on Mar 09, 2004 at 15:26 UTC

    Using

    #!/usr/bin/perl -w use strict; use diagnostics;
    instead of just
    #!/usr/bin/perl

    will help you enormously.

    You should get into the the habit of using those 3 lines for every script you write while you are learning. Regardless of how good you get, you should always use the first 2 lines.

    Just in case you missed it, I added -w to the first line.

    PN5

      Good advice, but with modern day Perl 5, it's better to just use warnings instead of -w
      use strict; use warnings;

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
      Thank you for the information Prior!
      I can use all the advice I can get.

      This is fun (but kinda hard so far)

      charles