Solved

Splitting a string

Posted on 2004-10-13
5
224 Views
Last Modified: 2010-03-05
Hi have a string

hostname.domain:abc="tag"

i want to get

$var1=hostname.domain
$var2=abc
$var3=tag

can someone help me on this

thanks
0
Comment
Question by:Vlearns
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:Vlearns
ID: 12305499
actually the problem is this:

i have @list containing hostname1.domain1:abc="tag" and
                                 hostname2.domain2:abc="tag"

i want @var1=hostname1.domain1,hostname2.domain2
          @var2=abc
           @var3=tag

Please suggest a solution, i am newbie to perl

Thanks
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 500 total points
ID: 12305552
I don't know the exact pattern of your data. For example, istag always made up of letters, or could there be numbers too? Anyway, this should get you started.

@list = qw{hostname1.domain1:abc="tag" hostname2.domain2:abc="tag"};
foreach $line ( @list )
{
      $line =~ /^(.*):(\w+)=\"(\w+)\"$/;
      $var1 = $1;
      $var2 = $2;
      $var3 = $3;

      print("var1: $var1  var2 : $var2  var3 : $var3\n");
      
      
}
0
 

Author Comment

by:Vlearns
ID: 12305564
tag is always letter like  tag="product"

0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 12305590
this code should work then, give it a go.
0
 

Author Comment

by:Vlearns
ID: 12305635
thanks tera

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question