Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Detecting URLs with URI

by Mr. Muskrat (Canon)
on May 26, 2016 at 20:21 UTC ( [id://1164226]=note: print w/replies, xml ) Need Help??


in reply to Detecting URLs with URI

  1. Pick a suitable default and use it if the URL doesn't contain a scheme.
  2. Allow URI->canonical to lowercase it.
Example code below:

#!/bin/env perl use strict; use warnings; use URI; for my $search ('http://www.foo.com', 'https://www.foo.com', 'www.foo. +com', 'WWW.FOO.COM', 'ftp://www.foo.com') { my $url = $search; # we can't modify $search directly $url = 'http://' . $url unless $url =~ m!^\w+://!; # If there isn't +a schema, add http:// my $uri = URI->new($url)->canonical->as_string; print "$search => $uri\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found