"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


In reply to Re^3: Downloads in firefox using perl WWW::Mechanize::Firefox by kcott
in thread Downloads in firefox using perl WWW::Mechanize::Firefox by pawaniitd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.