in reply to Re^2: Downloads in firefox using perl WWW::Mechanize::Firefox
in thread Downloads in firefox using perl WWW::Mechanize::Firefox

"The $FILES[2] is actually the first file in the directory as the first 2 elements of that array are '.' and '..'. I have tested it separately and it works."

Well, I wrote "[it] will be the third directory entry", so retorting with "[it] is actually the first file" comes across as purely argumentative. On a *nix system, '.' and '..' are files. Perhaps tell us what OS you're using.

Semantics aside, you're assuming that $FILES[2] will hold the correct filename for $old. Is that a reasonable assumption for the entire life of your script? How many people have access to "output/download" (including yourself)? Is it at all possible that any of those people could modify (even inadvertently) the contents of "output/download"? Is there a better way to generate the value for $old (perhaps based on the name of file currently being downloaded and a modification time)?

"When i add a print statement after the $mech->get() function, i do not get any output."

How is that relevant in a reply to my post? Assumimg it is somehow relevant, just stating "i add a print statement" is entirely insufficient information. What is this print statement?

"The use of : use strict; use warnings; does not give any error."

Copying the code you posted (verbatim) to a file (pm_example.pl) and adding use strict; use warnings;, perl -c pm_example.pl gives me

$ perl -c pm_example.pl Global symbol "$x" requires explicit package name at pm_example.pl lin +e 10. Global symbol "@list" requires explicit package name at pm_example.pl +line 10. Global symbol "$x" requires explicit package name at pm_example.pl lin +e 14. Global symbol "@FILES" requires explicit package name at pm_example.pl + line 17. Global symbol "@FILES" requires explicit package name at pm_example.pl + line 18. Global symbol "$new" requires explicit package name at pm_example.pl l +ine 19. pm_example.pl had compilation errors.

While you may have my @list before the loop (but forgot to show it); within the scope of the loop, the other variables listed in that perl -c output should be declared as lexical variables (probably using my).

As ++robby_dobby points out, when you fail to show your code we can only guess at what it might be. Given this is your first posting here, please familiarise yourself with the guidelines in "How do I post a question effectively?".

"The $old is set by getting the filename of the file that has been downloaded, so it is not the same value."

Incorrect. As I pointed out above, $old is based on the value of $FILES[2] (which has no guaranteed correlation with the download file).

-- Ken

Replies are listed 'Best First'.
Re^4: Downloads in firefox using perl WWW::Mechanize::Firefox
by pawaniitd (Initiate) on Mar 12, 2014 at 06:41 UTC

    I solved the problem. I realized that the $mech->get() function might be waiting for the page to load. But as i set Firefox to download the file automatically, there was no page being loaded. Thus, i set the function to not wait for response from browser and it worked.

    I thank you for helping me out. As this was my first post i made some error in reporting the problem and the code. Next time i will try to frame the question better and will keep your suggestions in mind before posting new questions.