Ok, now I understand better. You are using an existing DB, not making one? You need to use the Perl DBI - Data Base Interface. There are links to the FAQ's and some tutorials. You can see some Monk links here: https://www.perlmonks.org/?node=Tutorials#Database-Programming.
A wild guess and some untested example code would be:
Instead of printing the link, you would use your code to download that doc, then do whatever you are going to do with it.
Update: I see that you are using MySQL instead of SQLite. Brain cramp on my part. But code is essentially the same - just a difference in how to get the DB connection. The dbi would be: dbi::MySQL, then you need an account and password. For SQLite, these are null strings. See the doc's referenced above for a connection example with username/password.
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use DBI qw(:sql_types);
my $dbfile = "./YourDbName.sqlite";
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",{RaiseError =
+> 1})
or die "Couldn't connect to database: " . DBI->errstr;
my $get_links_4date_sql = "SELECT Identifer, LINK
FROM YourTableName
WHERE Publish date IS ?");
my $get_links_4date = $dbh->prepare ($get_links_4date_sql);
my $date = "20220701";
$get_links_4date->execute($date);
my $array_ref = $get_links_4date->fetchall_arrayref;
foreach my $row_ref (@$array_ref)
{
my ($id,$link) = @$row_ref;
print "$id \t $link\n";
}
I can't anticipate exactly what kind of SQL you need. Above just gets docs for a particular date. Although sounds like what you need
is: for each unique id, download latest version of the document. The SQL for that is of course more involved but doable.
Hope this gets you further along your way. |