$ff->file() is an unfortunate name, it is documented as "The name of the remote file". At least for HTTP, a document available via a URI might come from a database, or it might just be generated on the fly, so there might be no file at all.

Plus, calling $ff->file(...) before calling $ff->fetch(...) will change the source URI for at least some URI schemes and fetch methods, which is NOT the desired behaviour.

But: The documentation for $ff->file() has a second sentence, and that's the real hint:

For the local file name, the result of $ff->output_file will be used.

It might look like you could simply call $ff->output_file("document$i.pdf"), but a quick look into the source code shows that more work is needed:

sub output_file { my $self = shift; my $file = $self->file; $file =~ s/\?.*$//g; $file ||= $self->file_default; return $file; }

So, you need to replace output_file, either by monkeypatching or by inheriting from File::Fetch and replacing that method with one that returns the desired file name.

Or, if all you need is to fetch from HTTP or HTTPS, follow hippo's++ advice and use LWP::Simple.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: Rename/mkdir with File::Fetch by afoken
in thread Rename/mkdir with File::Fetch by justin423

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.