I posted a question on here before about File:Fetch and got a bunch of great responses, so thank you all...
It doesn't seem like this is possible, but can file:Fetch either rename the files to a particular filename, or alternatively create a new directory each time with a pre-determined folder name?
The URL's are in format www.example.com/document_id/document.pdf where document id is a unique number provided by the publisher.
So all the files to fetch are named document.pdf.
So that each successive document doesn't overwrite the previous one, I rename them to document0.pdf, document1.pdf using a loop to keep them unique. (see code below)
so is there a way to either change the filename to document_id.pdf or make a new directory of data/documents/document_id/ and save the document.pdf to that new folder?
I think file:fetch only takes one variable input. and won't work with SELECT DOCUMENT_ID,URL FROM LINKS
my $query = "select url FROM LINKS"; # << minor edit
my $sth = $dbh->prepare($query) or die "prepare: ".$dbh->errstr;
$sth-> execute() or die "execute: ".$dbh->errstr;
$i=0;
while (my $ref = $sth->fetchrow_hashref()) {
print "\nurl: $ref->{url}\n";
my $ff = File::Fetch->new(uri=>$ref->{url});
my $where = $ff->fetch( to => '/data/documents/');
my $error= $ff->error();
rename
("C:/data/documents/document.pdf","C:/data/documents/document$i.pdf");
($i++);
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.