counting '.' in a domain name

D

Dr Eberhard Lisse

Hi,

can someone point me to where I can read something about how I can
count the '.'s in a domain name, ie lisse.NA = 1 and www.lisse.NA =
2 and so forth, so I can weed out some subdomains from a list?

greetings, el
 
M

Marc Girod

can someone point me to where I can read something about how I can
count the '.'s in a domain name, ie lisse.NA = 1 andwww.lisse.NA=
2 and so forth, so I can weed out some subdomains from a list?

You don't mean...

perl -le '
print;
@dn = qw(lisse.NA www.lisse.NA);
for (@dn) {
@f = /(\.)/g;
print"$_: ", scalar @f;
}'lisse.NA: 1
www.lisse.NA: 2

....do you?
Marc
 
D

Dave Saville

Hi,

can someone point me to where I can read something about how I can
count the '.'s in a domain name, ie lisse.NA = 1 and www.lisse.NA =
2 and so forth, so I can weed out some subdomains from a list?

my $domain = 'a.b.com';
my $dots = () = $domain =~ m{\.}g;
print $dots;
 
B

Bjoern Hoehrmann

* Dr Eberhard Lisse wrote in comp.lang.perl.misc:
can someone point me to where I can read something about how I can
count the '.'s in a domain name, ie lisse.NA = 1 and www.lisse.NA =
2 and so forth, so I can weed out some subdomains from a list?

For this kind of question you can use the `perldoc` utility that ships
with your Perl distribution like so:

% perldoc -q count
Found in perlfaq4.pod
How can I count the number of occurrences of a substring within a
string?
There are a number of ways, with varying efficiency. If you want a
count of a certain single character (X) within a string, you can
use the "tr///" function like so:

my $string = "ThisXlineXhasXsomeXx'sXinXit";
my $count = ($string =~ tr/X//);
print "There are $count X characters in the string";

This is fine if you are just looking for a single character.
However, if you are trying to count multiple character substrings
within a larger ...
 
I

Ivan Shmakov

[Cross-posting to news:free.comp.dns.]
my $domain = 'a.b.com';
my $dots = () = $domain =~ m{\.}g;
print $dots;

Nice, thanks!

Please note, however, that in the most cases, the domain name
may also include an insignificant [*] trailing dot. Thus, it's
advisable to $domain =~ s/\.$// first.

[*] In fact, such a trailing dot denotes the "root" of the DNS tree,
thus distinguishing between relative (host.name) and absolute,
or fully-qualified, (host.name.example.org.) domain names. My
opinion is, however, that relative DNS names are better never to
be used, and what appears to be one is better to be treated as
if it's an absolute one.
 
D

Dr Eberhard Lisse

Thanks to all.

The trailing dot I had already removed :)-O

el

[Cross-posting to news:free.comp.dns.]
my $domain = 'a.b.com';
my $dots = () = $domain =~ m{\.}g;
print $dots;

Nice, thanks!

Please note, however, that in the most cases, the domain name
may also include an insignificant [*] trailing dot. Thus, it's
advisable to $domain =~ s/\.$// first.

[*] In fact, such a trailing dot denotes the "root" of the DNS tree,
thus distinguishing between relative (host.name) and absolute,
or fully-qualified, (host.name.example.org.) domain names. My
opinion is, however, that relative DNS names are better never to
be used, and what appears to be one is better to be treated as
if it's an absolute one.
 
R

Rainer Weikusat

Dr Eberhard Lisse said:
Thanks to all.

The trailing dot I had already removed :)-O

Perl has an idiom for counting characters in a string, namely, using
the tr/// operator with an empty replacement list, as in

perl -e '$a = "tear.mssgmbh.com"; print $a =~ tr/.//, "\n";'
 
D

Dr Eberhard Lisse

Thanks.

el

Perl has an idiom for counting characters in a string, namely, using
the tr/// operator with an empty replacement list, as in

perl -e '$a = "tear.mssgmbh.com"; print $a =~ tr/.//, "\n";'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top