Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Rename/mkdir with File::Fetch

by Corion (Patriarch)
on Aug 10, 2022 at 15:26 UTC ( [id://11146080]=note: print w/replies, xml ) Need Help??


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" );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-28 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found