LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Setting Headers for Web Pages in Perl (http://www.linuxquestions.org/questions/linux-general-1/setting-headers-for-web-pages-in-perl-833585/)

Hi_This_is_Dev 09-21-2010 11:39 AM

Setting Headers for Web Pages in Perl
 
There is an AIX 5.3 Box and there are some Perl scripts that generate web pages. We use them for monitoring of logs. But the perl script, let's name it "displayLogStatus.pl", that extracts some information such as "Failed", or "Completed" from specified log files doesn't refresh the page automatically.

In PHP I know how to refresh / reload a page after a specific time interval. For example this command in a web page:

PHP Code:

header("refresh:60"); 

would refresh the web page every 1 minute automatically.

How do we do that in Perl?

jangovich 09-21-2010 12:08 PM

Have you tried this:

Code:

#!/usr/bin/perl
print "Refresh: 10; url=http://www.example.com/\r\n";
print "Content-type: text/html\r\n";
print "\r\n";

Before any other contents gets printed out?

Hi_This_is_Dev 09-21-2010 01:14 PM

Refreshing a Web Page in Perl
 
Quote:

Originally Posted by jangovich (Post 4104709)
Have you tried this:

Code:

#!/usr/bin/perl
print "Refresh: 10; url=http://www.example.com/\r\n";
print "Content-type: text/html\r\n";
print "\r\n";

Before any other contents gets printed out?


Okay, here it is as suggested by you:

Code:

-bash-2.05b# cat sample.pl
#!/usr/bin/perl
print "Refresh: 10;\r\n";
print "Content-type: text/html\r\n";
print "\r\n";
print "This page refreshes every 10 seconds.\r\n";
open(DAT, "/tmp/sample.log") || die("Could not open the file: /tmp/sample.log");
@raw_data=<DAT>;
close(DAT);

print "<pre>";
foreach $everyLine (@raw_data) {
        print $everyLine;
}
print "</pre>";
-bash-2.05b#

Now let's try this:

Code:

-bash-2.05b# cal > /tmp/sample.log
-bash-2.05b# cal 2010 > /tmp/sample.log


We don't need to refresh the web page manually. It does it for us!

So, what is your fee? :hattip: Haha!!!

Thanks a lot!


All times are GMT -5. The time now is 01:34 PM.