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

This is my first ever perl/CGI question as so far I've been able to figure everything else out. I want to use CGI.pm to auto refresh a web page every 5 seconds. I can do this if I use perl to manually print the header but I'm already using CGI for cookies and redirects and really don't want to do things the hard way. Plus I want to understand what I'm missing. Here's some isolated code I've been working with. No errors, just doesn't refresh.
#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); print header; print start_html(-head=>meta({-http_equiv => 'Refresh', -content=> 'CO +NTENT=5; URL=http://someurl//thiscode.pl'})); print qq{<h1>Refresh damn you.</h1>}; print end_html;

Replies are listed 'Best First'.
Re: Using CGI.pm to auto refresh a web page
by cees (Curate) on Jan 30, 2004 at 23:47 UTC

    Why not send the real Refresh header instead of using the META tag.

    print header(-Refresh => "5;url=http://someurl//thiscode.pl");

    Or if you really want to do it in a META tag then try the following:

    print start_html(-head=>meta({-http_equiv => 'Refresh', -content=> '5; + URL=http://someurl//thiscode.pl'}));

    Or if you are paranoid, do them both :)

Re: Using CGI.pm to auto refresh a web page
by duff (Parson) on Jan 30, 2004 at 22:59 UTC

    I think you juse need -content => 5 rather than -content => "CONTENT=5"

    Update: I just relooked at your code. I didn't notice that you were really sending -content => "CONTENT=5; URL='...'". Replace all of that with -content => 5 though like I said :-)

Re: Using CGI.pm to auto refresh a web page
by CountZero (Bishop) on Jan 30, 2004 at 23:38 UTC
    Did you have a look at CGI::Push? It is a subclass of CGI and enables so-called server-push.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Using CGI.pm to auto refresh a web page
by b10m (Vicar) on Jan 30, 2004 at 22:58 UTC

    The META tags are HTML, not HTTP headers, so you'd probably want to push them into start_html(). I'm not aware of any "refreshing" HTTP headers.

    Update: I can't read, you did push them in the start_html() *DOH* So yes, like duff said, try -content => '5;http://someurl//thiscode.pl'. You can even drop the "URL" part, AFAIK.

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Using CGI.pm to auto refresh a web page
by crabbdean (Pilgrim) on Jan 30, 2004 at 23:25 UTC
    I've always found javascript solves some of these problems quite simply. Try the below.

    Dean
    <script language="javascript"> //the page will be refreshed every 10 seconds.. //the function refresh is called every 10 secs set Timeout('refresh()',10000) function refresh() { //this line does the actual reloading of the page window.location.reload(); } </script>
      That doesn't answer the OPs question, nor is it a solution (you should've kept it to yourself).