Solved

Splitting a string

Posted on 2004-10-13
5
230 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

687 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