Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Date::Manip::Recur is not returning a list

by desertrat (Acolyte)
on Jun 24, 2010 at 18:36 UTC ( #846370=perlquestion: print w/ replies, xml ) Need Help??
desertrat has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Date::Manip::Recur to generate a list of dates for a room scheduling application, and I'm having trouble getting it to work correctly.

Per the docs, there's an OO way and a functional way of doing this.

The functional way works:

#!/usr/bin/perl use Date::Manip; @date = ParseRecur("0:0:1*1,3,5:0:0:0","May 25 2010","6/1/2010","8/30/ +2010");# every MWF between the two dates. foreach $i (@date){ print "The date is $i\n"; } exit;

results in:

The date is 2010060200:00:00 The date is 2010060400:00:00 The date is 2010060700:00:00 The date is 2010060900:00:00 The date is 2010061100:00:00 The date is 2010061400:00:00 The date is 2010061600:00:00 The date is 2010061800:00:00 The date is 2010062100:00:00

and so on.

But

#!/usr/bin/perl use Date::Manip; print "Starting....\n"; $recur = new Date::Manip::Recur; $start = $recur->new_date(); $end = $recur->new_date(); $base = $recur->new_date(); $err=$start->parse("Jun 1 2010"); print "start err is $err \n"; $err=$end->parse("Aug 30 2010"); print "end err is $err \n"; $err=$base->parse("May 25 2010"); print "base err is $err \n"; $err=$recur->frequency("0:0:1*1,3,5:0:0:0"); print "freq err is $err \n"; @date = $recur->dates(); print "dates err is $err \n"; foreach $i (@date){ print "The date is $i\n"; } exit;

gives me:

Starting.... start err is 0 end err is 0 base err is 0 freq err is 0 dates err is 0

And nothing more.

I cannot even get the OO example given in the docs to work.

anyone here used this, and can point out my no doubt boneheaded mistake, before I bug the author?

Comment on Date::Manip::Recur is not returning a list
Select or Download Code
Re: Date::Manip::Recur is not returning a list
by andreas1234567 (Vicar) on Jun 24, 2010 at 19:34 UTC
    It would always be a good idea to enable strict and warnings.

    From looking at the tests it looks like parse returns a true/false value depending on parse success/failure, and not the actual date(s).

    $ perl -l use strict; use warnings; use Date::Manip; my $obj = new Date::Manip::Recur; my $err = $obj->parse( qw(1:2:3:4*12:30:00 2000010500:00:00 2000010100:00:00 2003010100:00:00 ) ); die $obj->err() if $err; my @dates = $obj->dates(); foreach my $date (@dates) { print $date->value; } __END__ 200015123000 2001330123000 2002624123000 $
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

      Yes, $recur->parse() only parses the recurrence string, it's $recur->dates() that returns the list of dates. What I don't understand is why it isn't in my case. Clearly it worked for you.

      When I try to replicate your code example, I get something new! I'm getting a list, but instead of a list of strings it's a list of hashes...

      #!/usr/bin/perl use strict; use warnings; use Date::Manip; print "Content-type: text/html \n\n"; print "Starting....<p>"; my $freq = "0:1:0*25:0:0:0"; my $mod = "DWD"; my $sday = "Jan 1 2010"; my $eday = "Dec 30 2010"; my $bday = "Jan 1 2010"; my $recur = new Date::Manip::Recur; my $err =$recur->parse($freq,$bday,$sday,$eday); print "parse err is $err <p>"; my @date = $recur->dates(); my $datenum = @date; print "There are $datenum list members <p>"; foreach my $i (@date){ print "The date is $i->value<p>"; } exit;
      Starting.... parse err is 0 There are 12 list members The date is Date::Manip::Date=HASH(0x8404c00)->value The date is Date::Manip::Date=HASH(0x83ff830)->value ...
      headdesk
        print "The date is $i->value<p>";

        Method calls don't interpolate.  You're interpolating just the value of $i (which is an object/hashref), and the "->value" prints as is. Try

        print "The date is ", $i->value, "<p>";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://846370]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-07-07 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls