CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [prateekm21] Regular expression to extract domain name: Edit Log



vikas.deep
User

May 2, 2009, 1:57 AM


Views: 4920
Re: [prateekm21] Regular expression to extract domain name

Hi Prateekm,
Hope you must have been benefited by other replies to your query. I was just going through the various responses to your query I tried the one suggested by one of our friends It works well for first eg in the query but fails in case of second query. It won't even compile if you "use strict". I can think of only two options
First do not "use strict" during compilation.
Second escape the $ symbols in the string $url.
Above all are you absolutely sure that you have spotted such a url which carries $symbols. The url you have mentioned took me to some USA.com In that site I tried a few links like "hotel reservation", "Car rental", "Airline reservation" but at least in these three cases I could not spot a $ in the url address.
You see the $ is a reserved symbol in PERL and that is the reason that $ is not acceptable in the variable $url during compilation.
Also I may add that if you are working on a large number of cases(URLs) then the ".com" loses its significance In that case a better approach will be to combine the two suggestions made by our friends i.e. first split at "\" and then again explode it into an array at the dot character. Now you can just discard the "com". In my example code I have escaped all the $. There might me a better solution because of "TMTOWDI" Unimpressed
#!/usr/bin/perl
use strict;
use warnings;

my $url = "http://test.usa.com/o/tA\$IXTq\$2ALoYduAJQs\$j.AJQRO-QA/nourl1";

my @arr = split(/\//,$url);


$arr[2] =~ s/^www.//;
my @arr2 = split(/\./,$arr[2]);
print "@arr2";

print "\n",$arr[2];
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

(This post was edited by vikas.deep on May 2, 2009, 2:03 AM)
Attachments: ment.pl (0.24 KB)


Edit Log:
Post edited by vikas.deep (User) on May 2, 2009, 2:03 AM: I oculd not see the attachment to my post so I copied the code and pasted it in my main post


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives