Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I don't understand, perldoc URI::URL made me think it should work
use URI::URL; print URI::URL->new( 'http://foo.com/bar/file.foo' )->file; __END__ Can't locate object method "file" via package "URI::http" ...

Replies are listed 'Best First'.
Re: Can't locate object method "file" via package "URI::http"
by ikegami (Patriarch) on Jul 10, 2008 at 19:13 UTC

    First of all, why are you using obsolete module URI::URL instead of URI? See the first line of the docs.

    Secondly, I don't see anything that suggests that URI::URL provides a file method. The local_path method might do the trick (misreferenced as localpath).

    Update: Nope, that only works for URIs using the file: scheme. The confusion is understandable since you're using an obsolete, undocumented module.

Re: Can't locate object method "file" via package "URI::http"
by Khen1950fx (Canon) on Jul 10, 2008 at 22:55 UTC
    First, listen to ikegami. Second, try this as a last resort:

    #!/usr/bin/perl use URI::file; my $file = URI::file->new( 'http://foo.com/bar/file.foo' )->file; print $file, "\n";
      sub URI::file { return (shift->path_segments)[-1] }
      doesn't work