Question

perl/cgi meta refresh question

Asked by: omcr

How do I get this:
<META HTTP-EQUIV="REFRESH" CONTENT="X;URL=yourpage.html">
Into the right syntax for the code below.

It's part of a a perl script that puts a text file on the webpage that is updated every 2min, I want to have the page refresh automatically.

#!/usr/bin/perl -w
use strict;
use CGI;

my $q = new CGI;

print $q->header( "text/html" ),
      $q->start_html ( -title => "Information", -bgcolor => "#ffffff" ),
      $q->end_html;

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-01-22 at 09:27:09ID21705768
Tags

refresh

,

meta

,

perl

,

cgi

Topic

CGI Scripting

Participating Experts
2
Points
60
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. PERL CGIs and Downloading files
    Hi all- On several sites that I have seen, they have a link to a cgi that starts a file downloading in your browser and then also causes a "Thank you" screen to appear in your main browser window. (The best example of this is what happens when you click on the &qu...
  2. Perl CGI
    Hi, I'm new in Perl/CGI world. I have a html page that contains a call to .cgi file. However, seems like it doesn't work. I did install a Sambar Web Server in my pc & load the cgi-lib.pl in my /cgi-bin directory. I have no ideas in solving this probs. test.html--->p...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: omcrPosted on 2006-01-22 at 09:32:45ID: 15760996

More info: the text file is updated whenever the perl script is run, the data the script uses to create the text file is updated every 2min, so I want the page to refresh every 2min to fire the perl script and get the new data into the text file and onto the website.

 

by: manav_mathurPosted on 2006-01-23 at 07:09:37ID: 15766961

$q->start_html ( -title => "Information", -bgcolor => "#ffffff"
                         -meta => {'HTTP-EQUIV'='REFRESH',
                                          'CONTENT'='X;URL=yourpage.html'}
                            ),

 

by: manav_mathurPosted on 2006-01-23 at 07:14:59ID: 15767027

forgot a comma, and also put ther number of seconds. ALso, for refresh of the same page, u dont need to code the optional URL

 $q->start_html ( -title => "Information",
                         -bgcolor => "#ffffff",
                         -meta => {'HTTP-EQUIV'='REFRESH',
                                          'CONTENT'='120'}
                            ),

 

by: omcrPosted on 2006-01-23 at 20:13:16ID: 15772906

I tried your suggestion, the error I'm getting is:
 Can't modify constant item in scalar assignment at c:\PROGRA~1\APACHE~1\apache\cgi-bin\weather\test\CURREN~1.PL line 12, near &quot;'REFRESH',&quot;
Execution of c:\PROGRA~1\APACHE~1\apache\cgi-bin\weather\test\CURREN~1.PL aborted due to compilation errors.

I think one issue may be that I trying to refresh a page that is created by a perl script, not a .html page.
 
I paste in the entire script which in the end just throws several lines of text onto a webpage. The script works fine without the refresh code in it. I'm using apache on a windows xp box.

Here it is

#!/perl/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Carp qw(warningsToBrowser);
use Time::Local;

my $q =new CGI;
print  $q->header( "text/html" ),
        $q->start_html ( -title => "Echo7 Current Conditions",
                                -bgcolor => ""#ffffff",
                                -meta => {'HTTP-EQUIV'='REFRESH',      
                                 'CONTENT'='120'}
                               ),
        $q->end_html;



open WEA, "C:/Program Files/HeavyWeather/currdat.lst" or die "Cannot open currdat.lst $!";
open DUMP, ">C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/dump.txt" or die " Cannot open dump.txt $!";

my @wea = <WEA>;
print DUMP @wea;
 
close WEA;
close DUMP;

open DUMP, "C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/dump.txt" or die " Cannot open dump.txt $!";
open DATA, ">C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/data.txt" or die " Cannot open data.txt $!";

my @raw = <DUMP>;

my @tod    = grep/actualisation/, @raw; #get timestamp
my @temp  = grep/deg_F/, @raw;         #get temperatures [0]in [1]out
my @hum   = grep/percent/, @raw;       #get humidity [0]in [1]out
my @pres    = grep/inHg/,@raw;             #get  pressure [0]abs [1]rel
my @winsp  = grep/mph/,@raw;            #get wind speed
my @windr  = grep/name=/,@raw;         #get wind direction

for (@tod)   {s#^.*"(\d+)".*#$1#};
for (@temp)  {s#^.*"(\d+.\d)".*#$1#};
for (@hum)   {s#^.*"(\d+)".*#$1#};
for (@pres)  {s#^.*"(\d+.\d+)".*#$1#};
for (@winsp) {s#^.*"(\d+.\d)".*#$1#};
for (@windr) {s#^name="(.*)".*#$1#};

chomp @hum;
chomp @pres;
chomp @winsp;
chomp @windr;


print DATA $tod[0];
close DATA;

open DATA, "C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/data.txt" or die " Cannot open data.txt $!";
open DATA2, ">C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/data2.txt" or die " Cannot open data2.txt $!";

my $ttt = <DATA>;
chomp $ttt;

#### Need to subtract 2208988860 from the weather stations timeststamp ####

my $timestamp = $ttt - 2208988860;
my $date = localtime $timestamp;

print DATA2 "$date\n";
print DATA2 "Indoor Temperature  $temp[0]";
print DATA2 "Outdoor Temperature $temp[1]";
print DATA2 "Indoor Humidity     $hum[0]%\n";
print DATA2 "Outdoor Humidity    $hum[1]%\n";
print DATA2 "Relative Pressure   $pres[1] inHg\n";
print DATA2 "Wind Speed           $winsp[0] mph\n";
print DATA2 "Wind Direction      $windr[1]\n";
 
close DATA2;

open DATA2, "C:/Program Files/Apache Group/Apache/cgi-bin/weather/test/data2.txt" or die " Cannot open data2.txt $!";

my @data2 = <DATA2>;

print "<pre>",@data2,"</pre>";

close DATA2;




 

by: omcrPosted on 2006-01-23 at 20:16:50ID: 15772919

The following   -bgcolor => ""#ffffff",
is in the script correctly as  -bgcolor => "#ffffff",

 

by: manav_mathurPosted on 2006-01-24 at 02:54:35ID: 15774347

$q->start_html ( -title => "Information",
                         -bgcolor => "#ffffff",
                         -meta => {'HTTP-EQUIV'=>'REFRESH',
                                          'CONTENT'=>'120'}
                            ),

 

by: ahoffmannPosted on 2006-01-24 at 03:52:04ID: 15774542

perl's CGI module has its own idea about meta tags, unfortunately :-(

print start_html(-head=>meta( -title => "Information", -bgcolor => "#ffffff", {-http_equiv => 'Refresh',  -content => 'X;URL=yourpage.html'}));

 

by: omcrPosted on 2006-01-24 at 18:54:13ID: 15783129

manav mathur,
 Your last comment returned this error when I tried it:     [Tue Jan 24 21:45:26 2006] [error] [client 192.168.10.7] malformed header from script. Bad header=Indoor Temperature  64.0: c:/program files/apache group/apache/cgi-bin/weather/test/currentfl.pl.        Which looks like progress to me since it at least got some info from the script.

ahoffman,
The error your suggestion returned:
[Tue Jan 24 21:41:58 2006] [error] [client 192.168.10.7] [Tue Jan 24 21:41:58 2006] CURREN~1.PL: Undefined subroutine &main::meta called at c:\\PROGRA~1\\APACHE~1\\apache\\cgi-bin\\weather\\test\\CURREN~1.PL line 9.\n


 

by: ahoffmannPosted on 2006-01-25 at 00:24:53ID: 15784236

> .. Undefined subroutine &main::meta called ..
either ther is a typo in your perl script, or you have a very ancient CGI.pm
silly question: did you use CGI;

 

by: manav_mathurPosted on 2006-01-25 at 01:44:56ID: 15784583

ahoffman, he/she is using OO form of CGI. so meta(....) should be replaced by $q->meta(...)

or

print $q->header("text/html");
print $q->start_html(
                      -title   => "Information",
                      -bgcolor => "#ffffff",
                      -head    => $q->meta ({-http_equiv => 'Refresh',
                                                          -content    => '120'
                                        })
                    );

 

by: ahoffmannPosted on 2006-01-25 at 03:23:47ID: 15784983

> .. using OO form of CGI ..
then just using start_html() should complain too .. (or was there a use CGI qw(start_html); I doubt ..)

 

by: manav_mathurPosted on 2006-01-25 at 06:31:46ID: 15786352

probably the author changes start_html to $->start_html. A meta function would be hard to identify by a person at first glance.

 

by: omcrPosted on 2006-01-25 at 07:41:51ID: 15787131

>..either ther is a typo in your perl script, or you have a very ancient CGI.pm
silly question: did you use CGI;..

The perl script works fine except for this refresh problem.
I am using CGI. Here is beginning of script,

#!/perl/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Carp qw(warningsToBrowser);

>..probably the author changes start_html to $->start_html. A meta function would be hard to identify by a person at first glance..

I have been trying all of your suggestions as they are shown in your comments.

 

by: ahoffmannPosted on 2006-01-25 at 08:01:42ID: 15787314

please post yor  "new" statement too

 

by: omcrPosted on 2006-01-25 at 08:33:23ID: 15787656

These are the last ones I tried, from memory no access at this time.

my $q =new CGI;
print  $q->header( "text/html" ),
        $q->start_html ( -title => "Information",
                                 -bgcolor => "#ffffff",
                                  -meta => {'HTTP-EQUIV'=>'REFRESH',
                                          'CONTENT'=>'120'}
                            ),
                  $q->end_html;


And for the other suggestion

my $q =new CGI;
print start_html(-head=>meta( -title => "Information", -bgcolor => "#ffffff", {-http_equiv => 'Refresh',  -content => '120'}));
       $q->end_html;

 

by: manav_mathurPosted on 2006-01-25 at 11:45:33ID: 15789512

How is it not working? Is it not refreshing the page after 2 mins or is it refreshing but not showing new/updated data?

 

by: ahoffmannPosted on 2006-01-25 at 12:48:51ID: 15790133

> .. -content => '120' ..
could not work 'caus your're missing the link

 

by: omcrPosted on 2006-01-25 at 13:41:50ID: 15790601

> .. How is it not working? .. The page never loads when I try to add the code we've been discussing. Without any of the refresh code the page loads fine will display this:

Wed Jan 25 16:34:23 2006
Indoor Temperature  72.5
Outdoor Temperature 54.3
Indoor Humidity     46%
Outdoor Humidity    26%
Relative Pressure   30.05 inHg
Wind Speed           0.0 mph
Wind Direction      WSW

> .. could not work 'caus your're missing the link .. If you mean the URL, I'm trying to refesh the same page everything is on and I have also tried with the URL, same results.

 

by: manav_mathurPosted on 2006-01-25 at 13:44:09ID: 15790622

do you get any error messages?

 

by: ahoffmannPosted on 2006-01-25 at 14:10:07ID: 15790827

ok, gets confusing now, lets start again.

Please answer following questions:

1. does following code work (please replace with a **valid URL**):

my $q =new CGI;
print  $q->header( "text/html" ),
        $q->start_html ( -title => "Information", -bgcolor => "#ffffff", -meta => {'HTTP-EQUIV'=>'REFRESH', 'CONTENT'=>'120; URL=http://replace-this'} ),
        $q->end_html;

2. does following code work (please replace with a **valid URL**):

my $q =new CGI;
print  $q->header( "text/html" ),
    $q->start_html(-title => "Information", -bgcolor => "#ffffff",-head=>$q->meta(  {-http_equiv => 'Refresh',  -content => '120; URL=http://replace-this'} ));
       $q->end_html;

3. please post error messages from your server, if any

 

by: omcrPosted on 2006-01-25 at 19:50:35ID: 15792569

Ok. First chance I've had to try new suggestions:

Manav Mathur > Date: 01/25/2006 01:44AM PST
Page loaded,,,,,,,,,,,,,,,,,,and is refreshing!!!!!!!!

Ahoffman > Date: 01/25/2006 02:10PM PST
Version 1- Page loaded but did not refresh. No errors in browser or server logs.

Version 2- Page loaded,,,,,,,,,,,,, and is refreshing !!!!!!!!!

Thank you both for your patience and effort.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...