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++);
}