counting '.' in a domain name

Discussion in 'Perl Misc' started by Dr Eberhard Lisse, Feb 25, 2013.

  1. 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
     
    Dr Eberhard Lisse, Feb 25, 2013
    #1
    1. Advertising

  2. Dr Eberhard Lisse

    Marc Girod Guest

    On Feb 25, 10:53 am, Dr Eberhard Lisse <> wrote:
    > 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
     
    Marc Girod, Feb 25, 2013
    #2
    1. Advertising

  3. Dr Eberhard Lisse

    Dave Saville Guest

    On Mon, 25 Feb 2013 10:53:05 UTC, Dr Eberhard Lisse <>
    wrote:

    > 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;

    --
    Regards
    Dave Saville
     
    Dave Saville, Feb 25, 2013
    #3
  4. * 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 ...
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
    25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Feb 25, 2013
    #4
  5. Dr Eberhard Lisse

    Ivan Shmakov Guest

    >>>>> Dave Saville <> writes:
    >>>>> On Mon, 25 Feb 2013 10:53:05 UTC, Dr Eberhard Lisse wrote:


    [Cross-posting to news:free.comp.dns.]

    >> 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;


    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.

    --
    FSF associate member #7257
     
    Ivan Shmakov, Feb 25, 2013
    #5
  6. Thanks to all.

    The trailing dot I had already removed :)-O

    el

    on 2013-02-25 13:54 Ivan Shmakov said the following:
    >>>>>> Dave Saville <> writes:
    >>>>>> On Mon, 25 Feb 2013 10:53:05 UTC, Dr Eberhard Lisse wrote:

    >
    > [Cross-posting to news:free.comp.dns.]
    >
    > >> 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;

    >
    > 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.
    >
     
    Dr Eberhard Lisse, Feb 26, 2013
    #6
  7. Dr Eberhard Lisse <> writes:
    > 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";'
     
    Rainer Weikusat, Feb 26, 2013
    #7
  8. Thanks.

    el

    on 2013-02-26 15:21 Rainer Weikusat said the following:
    > Dr Eberhard Lisse <> writes:
    >> 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";'
    >
     
    Dr Eberhard Lisse, Feb 26, 2013
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Infant Newbie
    Replies:
    2
    Views:
    3,258
    Infant Newbie
    Nov 12, 2003
  2. Joey
    Replies:
    0
    Views:
    350
  3. Patrick

    Getting windows user-name without domain name

    Patrick, Dec 7, 2007, in forum: ASP .Net Security
    Replies:
    2
    Views:
    541
    Nikolay Podkolzin
    Dec 14, 2007
  4. Chem Leakhina
    Replies:
    2
    Views:
    144
    Robert Klemme
    Jun 23, 2009
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    204
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page