Franklin wrote:
Hello:

Hello,

I have encounter a very strange problem. I have the following script:


always always always
use strict;
use warnings;

use LWP::Simple;
use URI;

$base_url="http://finance.yahoo.com";;
$filename="finance.htm";

my $base_url ... my $filename ...

since theirs no interpolation (IE no vars) use single quotes, its faster.

while(1)
{
my $status=getstore($based_url,$filename);
if(is_success($status)){
print "good\n";
}
else
{
print "bad\n";
}
sleep 300;
}

Also better indentation makes it tons more readable.

So this scipt is supposed to fetch the newest finance.yahoo.com
webpage every five minutes and store it. But everytime I started
it,waited for several hours and stopped it later, the stored
finance.htm is always the the first time captured file. What is wrong
with my scipt?(I run it at freebas platform)

Thank you very much in advance!
Franklin


#!/usr/bin/perl

use strict;
use warnings;

use LWP::Simple;
use URI;

my $base_url ='http://finance.yahoo.com';
my $filename ='finance.htm';

while(1) {
unlink $filename or die $!; # maybe copy the file and if it fails copy it back and if its ok remove the copy instead
my $status = getstore($based_url,$filename);
print is_success($status) ? "good\n" : "bad\n";
sleep(300); # or cron it every 5 minutes instead
}


since $status is only usedonce you could do:
print is_success( getstore($based_url,$filename) ) ? "good\n" : "bad\n";


HTH :)

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to