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

I using Schedule::Cron I'd like to determine the next excecution time in a detached process and write the time to a file. When $cron->get_next_execution_time(EVERY_MINUTE) runs in the subroutine UpdateFileOne I get the error Undefined subroutine &main::UpdateFile called at /usr/local/share/perl5/Schedule/Cron.pm line 1257. What I'm I doing wrong?

#!/usr/bin/perl use strict; use Schedule::Cron; use constant { EVERY_MINUTE => '*/1 * * * *' , EVERY_TEN_MINUTE => '0,10,20,30,40,50 * * * *' , EVERY_TEN_MINUTE_OFFSET => '3,23,25,35,45,55 * * * *' }; #Glolbal ##########*******************#################### our $cron = new Schedule::Cron(\&UpdateFile,'processprefix' => 'Index +Move'); our $cronId; #MAIN PROGRAM ##########*******************#################### $cronId = $cron->add_entry(EVERY_MINUTE,{'subroutine' => ,\&UpdateFile +One, 'arguments' => ["Passed"]}); $cronId = $cron->add_entry(EVERY_TEN_MINUTE_OFFSET, {'subroutine' => , +\&UpdateFileTen, 'arguments' => ["Passed"]}); sub UpdateFileOne { my $outputfile= '/home/allenrj1/scripts/updatefile.txt'; my $timestamp = localtime(time); my $passed_argument = $_[0]; my $next_time = $cron->get_next_execution_time('*/1 * * * *'); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +next_time); open MYFILE, ">>$outputfile" or die "problem opening $outputfile\n"; print MYFILE "Ran at $timestamp with $passed_argument\n"; printf "Next Time is: %02d:%02d:%02d\n", $hour,$min,$sec; close(MYFILE);

Replies are listed 'Best First'.
Re: Schedule::Cron determine next run time
by kcott (Archbishop) on Mar 03, 2014 at 19:37 UTC
    "I get the error Undefined subroutine &main::UpdateFile ... What I'm I doing wrong?"

    Exactly what the error message is telling you: you haven't defined UpdateFile().

    Look at the Schedule::Cron SYNOPSIS:

    sub dispatcher { ... } ... my $cron = new Schedule::Cron(\&dispatcher);

    -- Ken

Re: Schedule::Cron determine next run time
by talexb (Chancellor) on Mar 03, 2014 at 19:08 UTC

    You've passed in the address for UpdateFileTen, but you haven't defined it. That's what it's complaining about. Perhaps you've confused it with UpdateFileOne?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      "You've passed in the address for UpdateFileTen, but you haven't defined it. That's what it's complaining about."

      That's another problem but not the cause of the error: "Undefined subroutine &main::UpdateFile called at ..."

      -- Ken