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

Hi Monks

I am using mirror method to get the update webpage content

here is my code

if($mech->mirror("url","$filename") == RC_NOT_MODIFIED ) { print " link not Updated \n\n\n"; if($mech->response()->is_success){ print " response is success\n\n"; print " content :",$mech->response()->as_strin +g,"\n\n"; } else { print "failure \n\n"; } } else { print " link updated...\n\n"; $mech->save_content($filename); }

When i run this above code i get some irregular files except download file

# Command line output error Cannot rename '-23348' to '': No such file or directory $ls -23094 -23348 code.pl config.ini downloads downloads1 downloads2 + Download_Status.doc output.txt $ ls ./* -lthr 727 May 26 09:41 ./config.ini 9.2K May 26 09:54 ./code.pl 11M May 26 09:54 ./-23094 113 May 26 09:55 ./Download_Status.doc 26M May 26 10:04 ./-23348

my doubt is why am getting this "-23348" file and how can i get update page content???

Please Help me to find a correct path

Replies are listed 'Best First'.
Re: Problem in mirror method
by Corion (Patriarch) on May 26, 2016 at 06:11 UTC

    You did not show the value of $filename. If $filename is empty, you're likely to get this error.

    Maybe now is a good time to start with the Basic debugging checklist. That way, you can do many checks yourself without needing to wait for monks to reply.

      Sorry Corion i forget to mention file name, I am getting filename from http::response

      $res=$mech->res(); $filename=$res->filename(); # it has current web page filename

      The file name is not empty but i'm getting this error , Any Idea about this

        What makes you so certain that $filename is not empty?

        Does your program work if you hardcode the output filename?

        Did you print $filename just before your call to ->mirror()?

Re: Problem in mirror method
by Anonymous Monk on May 26, 2016 at 08:00 UTC

    Here is a demonstration of what the others are talking about

    use WWW::Mechanize; my $ua = WWW::Mechanize->new( autocheck => 1 ); $ua->show_progress(1); $ua->mirror( q{http://example.com/} , q{} ); __END__ ** GET http://example.com/ ==> 200 OK Cannot rename '-4056' to '': No such file or directory

    the empty string is not a valid filename

      Yeah it's working fine thanks Anonymous Monk

      but I need exact output if the page is updated then the program should return "modified" otherwise "not modified"

      Any Suggestion...