http://www.perlmonks.org?node_id=103746

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.

    -- TMTOWTDI

      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.