in reply to Steps to get a substring from a string

Depending on the parts you have already written and the functionality you need, Mozilla::PublicSuffix might help you to determine what is "a domain" and what is "a hostname in a domain".

If your question is only about string manipulation, have you considered using split on a dot and taking the first result?

my @parts = split /\./, $input;

Replies are listed 'Best First'.
Re^2: Steps to get a substring from a string
by vinoth.ree (Monsignor) on Jul 21, 2015 at 16:42 UTC
    Hi Corion

    How about the 2nd case,2) I have name=servername , i want to still capture the first part in a variable. In this your code will not work. we need to match a-zA-Z character after =

    my $str='name=host.com' my ($match) =$string=~/=([a-zA-Z]+)/;
    Update:

    Updated the regex part as per CountZero's node Re^3: Steps to get a substring from a string


    All is well. I learn by answering your questions...
      According to RFC952 and RFC-1123, the hostname should only consists of the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). Spaces and underscores are not allowed!

      Update: added "and underscores"

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
        ++CountZero

        Oh Sorry! Actually I considered only string part and written the script, I will update the same. Thank you CountZero


        All is well. I learn by answering your questions...