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

Please help with this NT script. I am trying to fetch the web site (which I will try and do every two or three hours) and get it loaded locally to a file called "cony.html". I even print the correct contents of the web site but it doesnt want to write the contents into "cony.html" I do have write permissions on "cony.html" and I dont get any messages saying "write failed".
use LWP::Simple; #use strict; #use warnings; my $url = 'http://website'; # get the HTML text my $content = get($url); if (not defined $content) { print "URL is not available.\n"; } else { print "Fetched data.\n"; } open(TMPFILE,">cony.html") || die "\nwrite failed: $!"; print TMPFILE "$content"; close TMPFILE; print "$content\n";

Replies are listed 'Best First'.
Re: Not writing to my local file.
by hiseldl (Priest) on Aug 28, 2002 at 17:09 UTC
    Try using getstore($url, $file).
    use LWP::Simple; my $url = 'http://website'; my $file = 'cony.html'; getstore($url, $file);
    I tried these on the command line and they worked:
    • ActiveState Perl in cmd.exe
      perl -MLWP::Simple -e "print getstore(\"http://localhost/
      \",\"x.html\")"
      
    • And Cygwin Perl in bash.exe
      perl -MLWP::Simple -e 'print getstore("http://localhost/","x.html")'
      

    note: this is from the POD docs for LWP::Simple.

    --
    hiseldl

Re: Not writing to my local file.
by Ovid (Cardinal) on Aug 28, 2002 at 17:10 UTC

    From perldoc LWP::Simple:

    getstore($url, $file)
      Gets a document identified by a URL and stores it in the file. The
      return value is the HTTP response code.

    I think you'll find that much easier.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Not writing to my local file.
by Snuggle (Friar) on Aug 28, 2002 at 17:21 UTC
    Just a caveat that I have.. you do not need the quotes around your content variable.
    This line:

    print TMPFILE "$content";

    should be
    print TMPFILE $content;
    Otherwise check you path to be very sure that it is absolute and correct
    Anyway, no drug, not even alcohol, causes the fundamental ills of society. If we're looking for the source of our troubles, we shouldn't test people for drugs, we should test them for stupidity, ignorance, greed and love of power.

    --P. J. O'Rourke
Re: Not writing to my local file.
by Anonymous Monk on Aug 28, 2002 at 17:12 UTC
    I dont want to waste your time because it was my path that was off. I needed to put in the absolute path to get it to work.