Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Identifying a Malformed URI

by Tuna (Friar)
on Aug 10, 2001 at 06:40 UTC ( [id://103746]=perlquestion: print w/replies, xml ) Need Help??

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

I have a config file, whose contents I need to test the sanity of. One of the checks I need to do, is to determine the syntactical validity of a URI. One requirement: it should not accomplish this by doing DNS queries. I didn't see anything apparent on CPAN, but this is the first time that I have considered this, so I may be missing something. Ideas?

Replies are listed 'Best First'.
Re: Identifying a Malformed URI
by tadman (Prior) on Aug 10, 2001 at 07:07 UTC
    You could use the URI module, which is part of LWP, and validate that way. You should check to see if it understood your request.
    use URI; my $uri = new URI ($some_uri);
    Then you can examine the contents of it to see if they are OK. Otherwise, you can use the "official" regexp to parse them. This is taken from the URI man page:
    my($scheme, $authority, $path, $query, $fragment) = $uri =~ m|^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#( +.*))?|;
Re: Identifying a Malformed URI
by trantor (Chaplain) on Aug 10, 2001 at 10:10 UTC

    If you only need to check whether the syntax is valid, you don't need DNS queries anyway.


      Heh, I wish it were that easy! These files contain DNS zone file entries for our customers, so performing a DNS query is vital to our process.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://103746]
Approved by root
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-05-21 20:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found