We help IT Professionals succeed at work.

Can Perl refresh a page?

akohan asked

I need to refresh a page from crontab. Can I use Perl if so then how?

Watch Question

Top Expert 2009
Is this related to: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23117283.html

You can have a perl script update a page from crontab.  Add this to your crontab:
*/10 * * * * /path/to/perl/script
(for every 10 minutes)

What is in the perl script will depend on exactly how you want the page updated.  Something like this:
use strict;
use HTML::Template;
my $t = HTML::Template->new(filename => 'index.tmpl');
open(OUT,">index.php") or die "could not open index.php: $!\n";
print OUT $t->output();

Open in new window



Yes, it is the same quesiton and now I found you have answered it using JavaScript.  But I first rather go with this solution (perl) since I'm using index.php on a server which is pretty restricted and even some javascript methods are blocked.

One thing that I have never done Perl and I got the following message which I ran above code:

Can't locate HTML/Template.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at update.pl line 3.
BEGIN failed--compilation aborted at update.pl line 3.

Any idea where I went wrong?


Top Expert 2009

The perl code will update the index.php file on the server - not cause the page to be refreshed in the browser.
The javascript in your other question will cause the page to be refreshed in the browser - not update the page on the server.

Which you use will depend on what you are trying to do.

The above error is telling you that the HTML::Template module is not installed.  If you want to have the perl script update the index.php page on the server, the code I gave is an example of a way to do that.  You will need to install the HTML::Template module.  From a prompt:  
    perl -MCPAN -e 'install HTML::Template'



Thanks for your help.