Modify Perl String in my Script

In my current Perl script I want to modify a string that identifies my database RAC zone cluster.  Currently using:  nslookup `hostname` to get my fully qualified hostname.  However, this is not the name I need to use for my network administration HOST string in my "tnsnames.ora" file.  So, please help me modify this string:
   
       An example   dbserver01.dpsn.local  -->  need this string to be  dbzonecluster.01.dpsn.local

In general I will always want to replace what comes before the first '.' character in the file with some predefined string.  Can't figure out how Perl function substr would help, or something like  $myZoneClusterName =~ s/xxxxx/yyyy/g
LVL 1
sdrussAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wilcoxonCommented:
If I'm understanding your question correctly, you want to change dbserverXX. into dbzonecluster.XX. - if so, this should work:
$myZoneClusterName =~ s{^\w+?(\d+)}{dbzonecluster.$1};

Open in new window

0
sdrussAuthor Commented:
wilcoxon:  looks good to me, I will check it out tomorrow morning.  Can you help me with the global regular expressions in your example.  I would like to learn more about regex.  Thanks.
0
wilcoxonCommented:
Sure.  s{...}{...} is just a safer way of doing s/.../.../ - there are fewer escapes necessary and it's harder to blow up the regex.
^ at the beginning anchors the regex to the beginning of the string
\w+? matches one or more "word" characters but as few as possible (called lazy)
(\d+) matches (and captures) one or more digits

In this case there is effectively an imaginary \. at the end of the match.

On the right-hand side:
dbzonecluster. is just the literal string
$1 matches the first capture - (\d+) in this case

If you wanted to be even more explicit, you could rewrite the left-hand side as:
^\w+?(\d+)(?=\.)

Open in new window

which adds a zero-width look-ahead for a period (eg it makes sure the character after the digits is a period but does not "consume" it so you don't need to add a period at the end of the right-hand side).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdrussAuthor Commented:
Thanks wilcoxon, absolutely everything I wanted.  Also, learned a lot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.