in reply to Re^3: Combining Ffile:fetch with MySQL
in thread Combining Ffile:fetch with MySQL

you are right. it doesn't print the url. it just exits after printing url: But the table has the correct url in the field url.

so this is the code where there is an issue.

while ($url = $query->fetchrow_array()) { print "url: $row->{url}\n"; # logic to get unique filename for output my $outfile = $path.$document_id; print $outfile; my $ff = File::Fetch->new( uri => url ); $ff->fetch(to => $outfile) or die "failed to fetch '$url' to '$outf +ile'.";

Replies are listed 'Best First'.
Re^5: Combining Ffile:fetch with MySQL
by justin423 (Scribe) on Jul 24, 2022 at 17:48 UTC
    ok. I am getting somewhere. here is the code:
    while (my $ref = $query->fetchrow_hashref()) { print "url: $ref->{url}\n"; my $ff = File::Fetch->new(uri=> '$ref' ); my $where = $ff->fetch(to => '/data'| \$scalar) ;

    when I run it with the where commented out, it prints the correct URL's, but errors out on each one with hostname required when fetching from ''

    running it with the $where uncommented, I get the same error, but it drops out on the first line of data with a can't call method Fetch on an undefined value.

      my $ff = File::Fetch->new(uri=> '$ref' );

      You have potentially 2 errors here. Firstly you are enclosing $ref in single quotes which prevent interpolation. Just lose the quotes entirely. Secondly, my understanding is that you need to pass $ref->{url} as the argument to new() rather than just $ref. Try those fixes and see if you get any further.


      🦛

        updated it to this and it prints all the links, but no saved files in the /data/ folder.
        while (my $ref = $query->fetchrow_hashref()) { print "url: $ref->{url}\n"; my $ff = File::Fetch->new(uri=>$ref->{url}); my $where = $ff->fetch( to => '/data/'); } $query->finish;