in reply to Re: URI Module can't find method
in thread URI Module can't find method

Here is the code

sub process_request { my $a = shift @_; if (not $a =~ m!^http://.*!) { $a = "http://$a" } my $url = URI->new($a); my $host = $url->host(); my $port = $url->port(); my $path = $url->path(); if ($port eq "") { $port = 80; } if ($path eq "") { $path = "/" } return ($host, $port, $path); }


The $a is www.cnn.com or anything like that.

Replies are listed 'Best First'.
Re^3: URI Module can't find method
by mojotoad (Monsignor) on Nov 17, 2004 at 22:55 UTC
    Are you sure $a will only be that? For example, 'ftp://blah.com' and 'https://somewhere.com' are valid strings for a URI which would blow up in your example since they use different schemes other than 'http'.

    Perhaps a better strategy would be to let the URI module do that work for you since that's what it does best:

    my $str = shift @_; my $uri = URI->new($str); $uri->scheme('http') unless $uri->scheme; ...

    Cheers,
    Matt