in reply to URI Module can't find method

I bet $a is a relative uri or not a uri at all. Update: Or maybe the URI uses a scheme URI.pm doesn't recognize.

use URI (); $uri = URI->new('index.pl'); print('Host of Relative URI ', $uri->as_string(), ':', $/); eval { print($uri->host(), $/); }; print($@) if ($@); print($/); $uri = URI->new('www.perlmonks.com'); print('Host of something (', $uri->as_string(), ') that isn\'t a URI a +t all:', $/); eval { print($uri->host(), $/); }; print($@) if ($@); print($/); $uri = URI->new('ikegami://www.perlmonks.com/'); print('Host of a URI (', $uri->as_string(), ') whose scheme URI.pm doe +sn\'t recognize:', $/); eval { print($uri->host(), $/); }; print($@) if ($@); print($/); $uri = URI->new('http://www.perlmonks.com/'); print('Host of Absolute URI ', $uri->as_string(), ':', $/); eval { print($uri->host(), $/); }; print($@) if ($@); print($/); $base_uri = URI->new('http://www.perlmonks.com/'); $rel_uri = URI->new('index.pl'); $abs_uri = $rel_uri->abs($base_uri); print('Host of Relative URI ', $rel_uri->as_string(), ' converted to a + Absolute URI using Base URI ', $base_uri->as_string(), ':', $/); eval { print($abs_uri->host(), $/); }; print($@) if ($@); print($/); __END__ output ====== Host of Relative URI index.pl: Can't locate object method "host" via package "URI::_generic" (perhaps + you forgot to load "URI::_generic"?) at !.pl line 5. Host of something (www.perlmonks.com) that isn't a URI at all: Can't locate object method "host" via package "URI::_generic" (perhaps + you forgot to load "URI::_generic"?) at !.pl line 11. Host of a URI (ikegami://www.perlmonks.com/) whose scheme URI.pm doesn +'t recognize: Can't locate object method "host" via package "URI::_foreign" (perhaps + you forgot to load "URI::_foreign"?) at !.pl line 17. Host of Absolute URI http://www.perlmonks.com/: www.perlmonks.com Host of Relative URI index.pl converted to a Absolute URI using Base U +RI http://www.perlmonks.com/: www.perlmonks.com

Replies are listed 'Best First'.
Re^2: URI Module can't find method
by RobertJ (Acolyte) on Nov 17, 2004 at 22:01 UTC
    " I bet $a is a relative uri or not a uri at all."

    $a is a uri. I got this script from the CS department at UNC and I know it works. My only problem is that my hosting company didn't have URI installed to I had to install it locally in my domain.

    My host uses Apache on Unix.

    "perhaps you forgot to load "URI::_generic?"

    I loaded the entire URI module including all 40+ supporting packages.

      Another possibility is that the URI is of a scheme URI.pm doesn't recognize. What does $a contain?

      >perl -MURI::HTTP -e'' >perl -MURI::ikegami -e'' Can't locate URI/ikegami.pm in @INC (@INC contains: ...). BEGIN failed--compilation aborted.