Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Fetch Problem uri

by Perlbotics (Archbishop)
on Jul 04, 2015 at 09:51 UTC ( [id://1133136]=note: print w/replies, xml ) Need Help??


in reply to Fetch Problem uri

Works for me when I remove the leading whitespace from $url ;-)

Update (2nd question - see below): Change destination filename.

Seems, that the module did not provide a setter-method to change the output_file()? I'll notify the author later...

This monkeypatch should correct that:

#!/usr/bin/perl use strict; use warnings; use File::Fetch; my $url="http://www.ekey.net/downloads-475?download=2132cbe2-2fb1-eeff +-583c-50a39b6aba6c&name=v2_ITA_12-Seiter_Programm_1207_web$ print "Downloading $url\n"; my $ff = File::Fetch->new(uri => $url); { #-- ugly patch package File::Fetch; print "PATCHED: ", __PACKAGE__, " version $VERSION!\n"; #-- patche +d line#0 sub output_file { my $self = shift; my $file = $self->file; $self->{_out} = $_[0] if $_[0]; #-- patche +d line#1 return $self->{_out} if $self->{_out}; #-- patche +d line#2 $file =~ s/\?.*$//g; $file ||= $self->file_default; return $file; } } package main; print "Before: ", $ff->output_file,"\n"; $ff->output_file("i-probably-violate-terms-of-use.pdf"); #-- or extra +ct name from URI using a regex print "After : ", $ff->output_file,"\n"; my $where = $ff->fetch( to => "ekey corpus" ) or $ff->error;
Result:
... PATCHED: File::Fetch version 0.48! Before: downloads-475 After : i-probably-violate-terms-of-use.pdf ...
Fixing this problem by use of parent is left as an exercise to the AM...

Replies are listed 'Best First'.
Re^2: Fetch Problem uri
by Anonymous Monk on Jul 04, 2015 at 10:01 UTC

    Oh, what an idiot! Thank you.

    There is anyway I smaller problem. The filename is wrongly parsed so that I get a file called downloads-475 (without .pdf). Any idea why? Or do I just have to try to parse it correctly by myself?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found