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

In reply to Re: URI Module can't find method by ikegami
in thread URI Module can't find method by RobertJ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.