in reply to LWP::Simple Empty File

The LWP::Simple docs indicate that you can look at the response code:
my $rc = getstore('http://www.perlmeme.org', 'some_local_file'); print status_message($rc), "\n";
This prints OK for me, and I get a non-empty oputput file.

Replies are listed 'Best First'.
Re^2: LWP::Simple Empty File
by idlemind (Initiate) on Mar 03, 2012 at 20:19 UTC

    Thanks for the quick response. I added the status_message snippet and get "OK". This works fine on my Linux machine but is giving me an empty file on Windows 7 machine. I installed Strawberry Perl 5.10.1.5 and have version LWP 5.837. I am sure it is something stupid that I am missing.

    #!/usr/bin/perl use strict; use warnings; use LWP::Simple; my $rc = getstore('http://www.perlmeme.org', 'some_local_fi +le'); print status_message($rc), "\n"; getstore('http://www.perlmeme.org', 'some_local_file'); exit 0;
      As per suggestion from Corion, what happens when you run this?

      The HTTP return code is not available for get() without using the LWP::UserAgent OO interface, but this 3 lines of code should ensure that your Windows box is actually getting something (runs on my XP Perl 5.10.1). If this prints something, then it comes down to probable file naming or permission errors in your getstore() statement.

      It is hard for me to understand how a new file could be created with no content if the RC is 'OK'. That would imply that you do have the permission to create the file in the first place and therefore have permission to write to it!
      Testing Note: delete your "blank" output file between runs to make sure that it is actually being created and not an artifact of some previous run.

      Anyway run this simple test and report back.

      #!/usr/bin/perl -w use strict; use LWP::Simple; my $content = get("http://perlmonks.org/?node_id=957704"); die "blank content" unless defined $content; print $content;

        Nothing is printed when I run the test above. I do notice that there is a very slight lag before it goes back to the command prompt. Anything else I should try?

      Works fine for me fetching http://perlmonks.org/?node_id=957704 on Windows XP using ActiveState Perl 5.10.1. I doubt very much that it is either the build of Perl or the OS.

      True laziness is hard work