Professional Web Applications Themes

why can't getstore function overwrite the existing file? - PERL Beginners

Hello: I have encounter a very strange problem. I have the following script: use LWP::Simple; use URI; $base_url="http://finance."; $filename="finance.htm"; while(1) { my $status=getstore($based_url,$filename); if(is_success($status)){ print "good\n"; } else { print "bad\n"; } sleep 300; } So this scipt is supposed to fetch the newest finance. 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...

  1. #1

    Default why can't getstore function overwrite the existing file?

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

    use LWP::Simple;
    use URI;

    $base_url="http://finance.";
    $filename="finance.htm";
    while(1)
    {
    my $status=getstore($based_url,$filename);
    if(is_success($status)){
    print "good\n";
    }
    else
    {
    print "bad\n";
    }
    sleep 300;
    }

    So this scipt is supposed to fetch the newest finance.
    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
    Franklin Guest

  2. #2

    Default RE: why can't getstore function overwrite the existing file?



    you have using "$based_url" variable in my
    $status=getstore($based_url,$filename); but you have declare "$base_url"

    it's always better using 'use strict' and warnings pragma...



    -----Original Message-----
    From: Franklin [mailto:com]
    Sent: Monday, October 11, 2004 3:18 PM
    To: org
    Subject: why can't getstore function overwrite the existing file?


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

    use LWP::Simple;
    use URI;

    $base_url="http://finance.";
    $filename="finance.htm";
    while(1)
    {
    my $status=getstore($based_url,$filename);
    if(is_success($status)){
    print "good\n";
    }
    else
    {
    print "bad\n";
    }
    sleep 300;
    }

    So this scipt is supposed to fetch the newest finance.
    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

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


    Raymond Guest

  3. #3

    Default Re: why can't getstore function overwrite the existing file?



    Franklin wrote: 

    Hello,
     


    always always always
    use strict;
    use warnings;
     

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

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

    Also better indentation makes it tons more readable.
     

    #!/usr/bin/perl

    use strict;
    use warnings;

    use LWP::Simple;
    use URI;

    my $base_url ='http://finance.';
    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
    JupiterHost.Net Guest

Similar Threads

  1. Publish PDF won't overwrite current file
    By msisson in forum Macromedia Contribute Connection Administrtion
    Replies: 1
    Last Post: January 25th, 07:13 AM
  2. Overwrite existing file with a template
    By g davies in forum Macromedia Contribute Connection Administrtion
    Replies: 2
    Last Post: March 3rd, 02:36 AM
  3. overwrite to file
    By Jonny T in forum PHP Development
    Replies: 3
    Last Post: June 15th, 11:00 PM
  4. Overwrite file if it exist
    By Mr. Smith in forum ASP Components
    Replies: 2
    Last Post: July 15th, 05:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139