in reply to Rename/mkdir with File::Fetch

The documentation of File::Fetch suggests no way to specify the name of the output file. Since you already have the ID, I suggest creating a directory for each ID and saving the file there:

my $id = $ref->{document_id}; my $dir = "/data/documents/$id"; mkdir $dir or die $!; my $ff = File::Fetch->new(uri => $ref->{url}); $ff->fetch( to => $dir );

Replies are listed 'Best First'.
Re^2: Rename/mkdir with File::Fetch
by justin423 (Scribe) on Sep 14, 2022 at 01:55 UTC
    I got this to work.
    my $tmp_dir='/data/documents/'; while (my $ref = $query->fetchrow_hashref()) { print "url: $ref->{url}\n"; my $id = $ref->{document_id}; my $dir = "/data/documents/"; # mkdir $dir or die $!; my $ff = File::Fetch->new(uri => $ref->{url}); $ff->fetch( to => $dir ); rename("$tmp_dir/document.pdf", "$tmp_dir$id.pdf") || die ( "Error in + renaming" );