Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: URI Module can't find method

by mojotoad (Monsignor)
on Nov 17, 2004 at 22:33 UTC ( [id://408632]=note: print w/replies, xml ) Need Help??


in reply to URI Module can't find method

The actual URI subclass that gets loaded depends on the scheme (for a string) or the type of object being passed to the constructor. Can you give an example of the type of url you're trying to load?

Matt

Replies are listed 'Best First'.
Re^2: URI Module can't find method
by RobertJ (Acolyte) on Nov 17, 2004 at 22:47 UTC
    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.
      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-24 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found