Split domain and tld from domainname

140 views
Skip to first unread message

yamaka...@gmail.com

unread,
Sep 8, 2014, 5:31:16 AM9/8/14
to puppet...@googlegroups.com
HI,


I'm facing an issue where I need to grab the tld and domain from a domainname no matter how many subdomains there are.


SO far I have tried regsubstr() and split() where split is getting where I want, but not fully yet:

$split = split("sub.sub.sub.domain.tld", '[.]')

The following gives me in any case the tld

$tld = $split[-1]

But as split works from left to right I cannot use $split[1]

Is there any way to solve this ?

Thanks!

Matt

Sebastiaan van Steenis

unread,
Sep 8, 2014, 5:53:50 AM9/8/14
to puppet...@googlegroups.com
Hi Matt,

As stated here (https://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#indexing), arrays support negative indexing. Is this what you are looking for?

$dom = $split[-2]


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b94dbe3f-0d3f-4417-bf1b-89e1fd65c70d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yamaka...@gmail.com

unread,
Sep 8, 2014, 8:52:43 AM9/8/14
to puppet...@googlegroups.com, pup...@superseb.nl
Hi Sebastiaan,

Thank you, I sorted it already out this way indeed!

Cheers,

Matt

Op maandag 8 september 2014 11:53:50 UTC+2 schreef Sebastiaan van Steenis:
Reply all
Reply to author
Forward
0 new messages