Help!

Perl Help


Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Web Developers RSS
Next:  So Who Is She Talking To?  
Author Message
Midnighter



Joined: Apr 10, 2003
Posts: 14



PostPosted: Sun Apr 02, 2006 11:33 pm    Post subject:

Hi there,

I'm in need of a little perl programming help.

I've like to add a piece of code to a perl script I have that detects if the text contained within a variable is a subdomain, for example subdomain.domain.ext, then if the condition is true it changes the text into just domain.ext before assigning it back to the variable, else it just leaves the text contained in the variable alone.

Any suggestions how I can go about this?

Thanks
Back to top
silmaril8n



Joined: Jan 29, 2004
Posts: 1743

Location: Phoenix, AZ

PostPosted: Sun Apr 02, 2006 11:58 pm    Post subject:

I don't know the Perl syntax but can't you explode the string with the "." as a separator? Then you can just use the TLD and Domain and ignore anything behind.
Back to top
AIM Address
Midnighter



Joined: Apr 10, 2003
Posts: 14



PostPosted: Thu Apr 06, 2006 1:32 pm    Post subject:

Quote:

I don't know the Perl syntax but can't you explode the string with the "." as a separator? Then you can just use the TLD and Domain and ignore anything behind.


Thanks silmaril8n, that's what I was thinking to, but until now I didn't know how to do it in code.

If anyone else wonders how it do this it turns out it can be done in 4 lines of code:

-=SNIP=-

$subdomain = "sub.subdomain.domain.net";
@domainwork = split(/\./, $subdomain);
$domain= "$domainwork[-2].$domainwork[-1]";

print "Domain: $domain\n";

-=/SNIP=-

$subdomain can be set to any lenth, for example sub.sub.sub.sub.subdomain.net and it will still only output domain.net.

Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Web Developers All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum